Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format fields in multiple files to Comma separated format.

Status
Not open for further replies.

galger

MIS
Jan 16, 2002
79
US
In need script for taking field's from multiple files in one directory

All files have the same "fields".

example file:
---------------------
##### TEST NAME : xxxxxxxx
##### TEST OWNER : XXXxxxxxx
##### XXX DIGIT IDENTIFIER : AAA, AAA, AAA
---------------------


Need format , separated starting with the FILENAME in the first field:

Need format to look like this
------------------------
FILENAME, TEST NAME, xxxxxxxx, xxxxxxxx, AAA, AAA, AAA
FILENAME, TEST NAME, xxxxxxxx, xxxxxxxx, AAA, AAA, AAA
FILENAME, TEST NAME, xxxxxxxx, xxxxxxxx, AAA, AAA, AAA
FILENAME, TEST NAME, xxxxxxxx, xxxxxxxx, AAA, AAA, AAA
------------------------

Hoping someone can help here

Given two equally predictive theories, choose the simpler.
 
What have you tried so far?

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Here is my script

#!/usr/bin/sh

for mailbox in `ls list`

do
MAILBOXNAME=`grep "XXXXX NAME" $mailbox | awk '{print $NF}'`
MAILBOXOWNER=`grep "XXXXX OWNER" $mailbox |awk '{print $NF}'`
IBD3DIGITIDENTIFIER=`grep "XXX 3 DIGIT IDENTIFIER" $mailbox | awk '{print $NF}'`

echo "$MAILBOXNAME,$MAILBOXOWNER,$IBD3DIGITIDENTIFIER" >>/tmp/outfile.xls
done


Every line looks like this basically

example:

##### XXXXX OWNER : XXXurxxx Xxxxx Xxxx


What I need to figure out is, how in awk, can I print "all data" after a colon :




Given two equally predictive theories, choose the simpler.
 
If you prefer to write it in shell and awk, why are you posting in the Perl forum?

What is list? A filename? If so, the result of that will be for mailbox in list, so it will only attempt to process one mailbox called "list". Perhaps you meant for mailbox in `cat list` or for mailbox in $(<list).

You can specify a different field separator in awk using the -F option, so if you make that a colon you can use the second field to get everything after it.

Also you don't need both grep and awk, since awk can do the filtering for you... but if you want to carry on this discussion we should move it over to the awk forum.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top