Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to parse a large file for information

Posted on 2009-04-13
8
Medium Priority
?
233 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 48

Expert Comment

by:Tintin
ID: 24142417
awk -F, '{printf "%-10s\t%s\n",$4,$9}' inputfile
0
 
LVL 20

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 20

Accepted Solution

by:
simon3270 earned 2000 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

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!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Suggested Courses

618 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