Solved

how to parse a large file for information

Posted on 2009-04-13
8
225 Views
Last Modified: 2013-12-26
I need to get information from a master file that contains user names and machines.
The 4th field contains the usernames and the 9th field contains systems that the user has access to.
My task is to create a list in 2 columns ( user host) that will list a user and every machines he/she has access to. The username will be repeated for each machine in the file.
i  am looking for a simple script that can accomplish this.Can any scripting guru please help?
Thanks in advance.
0
Comment
Question by:nesiuna_1
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 24134340
initially, you could do:

awk '{print $1, $9}' filename

if you can provide sample file data then script can be improved
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24135073
Please give some sample input/output.
0
 

Author Comment

by:nesiuna_1
ID: 24140330
this is the input file:
+gshepher:Yi/mOb6QeRcaU:5032:Greg Shepherd:/home/gshepher:/usr/bin/tcsh::staff,develop:ap1-bb15,ap1-bb15ua
t,ap1-chase,ap1-chasebb,ap1-cvmssm,ap1-gpcorr,ap1-gpmor,ap1-gprc
i need to parse the 4th field and the 9th field.
The 4th field is the username and the 9th field is the hostnames
what i need is a printout in this format:
User                                       Hostname
user1                                      host1
user1                                      host2
user2                                      host1
user2                                      host2
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24142417
awk -F, '{printf "%-10s\t%s\n",$4,$9}' inputfile
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:simon3270
ID: 24143388
awk -F: 'BEGIN{printf "%s\t%s\n","User","Hostname"}{printf "%s\t%s\n",$4,$9}' inputfile

(-F: because colon is the field separator)
0
 

Author Comment

by:nesiuna_1
ID: 24154448
The output of this script is this:
Felix Roytfeld  ap8-qa,perfap1-dv,perfdb1-dv,perfwb1-dv,sjcapp05

But what i am looking for something like this:
User                       Host
Felix Roytfeld        ap8-qa
Felix Roytfeld        perfap1-dv
Felix Roytfeld        perfb1-dv
Felix Roytfeld        sjcapp05

How can i the program to print out in this format?
Thanks
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 24155459
Please try:

  awk -F: 'BEGIN{printf "%s\t%s\n","User","Hostname"}{split($9,hosts,",");for (h in hosts) printf "%s\t%s\n",$4,hosts[h]}' infile
0
 

Author Closing Comment

by:nesiuna_1
ID: 31569744
Thank you very much for your professional help.
i really appreciate the timely response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 108
how awk substr works and also how index works in inside substr? 4 78
ROboscript to move a file to another Servers Directory 10 60
Message not shown 5 33
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now