Solved

how to parse a large file for information

Posted on 2009-04-13
8
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Tintin
ID: 24142417
awk -F, '{printf "%-10s\t%s\n",$4,$9}' inputfile
0
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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