Solved

how to parse a large file for information

Posted on 2009-04-13
8
226 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell backup 2 123
Unix/bash: scripted arithmetic 13 99
how to run my script during boot in rhel 7 14 147
Problem logging tar errors 11 57
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…
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.

786 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