Solved

how to parse a large file for information

Posted on 2009-04-13
8
224 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

758 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

20 Experts available now in Live!

Get 1:1 Help Now