script help needed --- awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script help needed --- awk?
# 1  
Old 06-19-2008
script help needed --- awk?

hello and thanks in advance.

I need to consolidate 2 records of data into 1 record.

here is a sample of the input:
------------------------------------------------------------------------------------------
totalcount fred thomas 99999.00 88888:00
total 77777.00
------------------------------------------------------------------------------------------
totalcount sally smither 99999.00 88888:00
total 77777.00 66666.00
------------------------------------------------------------------------------------------

Sample records are grouped within the '-------'. I need the data within the '---------' consolidated to look like the output format below

Fred, Thomas, 77777.00, 99999.00, 888888:00
Sally, Smither, 77777.00, 99999.00, 888888:00

Last edited by scuderiaf1; 06-21-2008 at 10:44 AM.. Reason: simplified the sample data
# 2  
Old 06-20-2008
If I got it right, just remove the ------ lines and the empty ones, right?
Code:
grep -vE "^------|^$" infile > newfile

# 3  
Old 06-20-2008
zaxxon


Yes that is one of the things needed. I now under stand the -v and -E args of grep. ty.

I still need to consolidate a couple of fields on each record in between the '------' to one record...... does that make sense?

I have a base awk statement that i have started. I piped your recommended grep command to it.


Code:
grep -vE "^------|^$" $FILENAME | awk '$4="04" { print $1","$2 }'


Last edited by scuderiaf1; 06-21-2008 at 10:35 AM..
# 4  
Old 06-21-2008
I have a little time this morning to work on this script... any help would be appreciated. I will be posting the solution.


Go Ferrari!
# 5  
Old 06-21-2008
Code:
awk 'BEGIN{RS="-+"; OFS=", "} $2 {print $2, $3, $7, $4, $5 }' your-file

# 6  
Old 06-21-2008
ty.... that works.

I am attempting to read/learn about the important parts of that script/command. Is is a true statement that awk considers everthing between the record seperator RS as one record?

Wow clean and simple.

Again thank you and regrards,

T

I've sat at the beginning of Eau Rouge. That circuit is in a magical place.
# 7  
Old 06-21-2008
A pure Korn shell solution
Code:
#!/usr/bin/ksh93

typeset -L1 -u firstF
typeset -L1 -u firstL

while read a b c d e
do
   if [[ $a == "totalcount" ]]; then
       nameF=$b
       nameL=$c
       numD=$d
       numE=$e
   fi
   if [[ $a == "total" ]]; then
       firstF=$nameF
       firstL=$nameL
       print "${firstF}${nameF#?}, ${firstL}${nameL#?}, $b, $numD, $numE"
   fi
done < file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - help needed please

Hi.. have a file as below, appreciate if someone can help on this 143|500| 10| 23353 22131 23355 23354 23358 23352 23357 23350 23349 23351| RAID5 213|1008| 9| 22419 22412 221 22413 22414 22416 22417 22415 22418| RAID6 1088|500| 5| 22243 22240 22244 22242 22241| RAID5 322|1200| 12|... (6 Replies)
Discussion started by: richard0@rediff
6 Replies

2. Shell Programming and Scripting

Simple awk script needed

but I'm stumped...please help I have a file like this....... 1000 1 34 1000 10 34 1000 11 35 1000 20 35 1000 21 36 1000 30 36 2000 1 34 2000 10 34 which I would like printed out as 40 lines 1000 1 34 1000 2 34 1000 3 34 1000 4 ... (2 Replies)
Discussion started by: garethsays
2 Replies

3. Shell Programming and Scripting

awk help needed

Hi, i have input records as shown below. 4097,Probe3,G10,255,05/17/2011 12:44:03:185,NULL,05/17/2011 12:39:03:180,05/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

4. UNIX for Dummies Questions & Answers

Help Needed with AWK

I have a source file (sample below) that I'm trying to standarize into a text file with pipe delimited currently I'm looking at the file as space delimited.... :wall: I have one issue that I don't know how to handle - in the second set of " " is a filename along with the path - most cases that... (2 Replies)
Discussion started by: DebDor
2 Replies

5. Shell Programming and Scripting

Awk Help needed

hi, I have input file woth records as shown below OCSMRC_OK,7057348733,+0.00,0,18/05/2010 23:42:19,BellMobility,302610000918553,0006056099,B30,686505,686505,OCS_MRC,+49.14,0,0 ,0,0, OCSPPKB_NOK,4163460120,+1.25,0,18/05/2010... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

6. Shell Programming and Scripting

awk help needed

How do I alter this command so that it prints only the second comma delimited field from line number 3? Secondly, how do you redirect the output to a variable called TEST? Thanks (cat BATCH007.TXT | awk 'BEGIN { FS = "," } ; {print $2 }') (5 Replies)
Discussion started by: ddurden7
5 Replies

7. UNIX for Dummies Questions & Answers

Awk help needed..

I have to add number in column 1 by month. 1531 Feb 1 2007 pgaps_p007_27909.trc 1529 Feb 1 2007 pgaps_p006_27907.trc 1533 Feb 1 2007 pgaps_p005_27905.trc 635 Apr 7 2007 pgaps_smon_2347.trc 634 Apr 7 2007 pgaps_lgwr_2343.trc 634 Apr 8 2007 pgaps_lgwr_2311.trc 613 Apr 10 2007... (4 Replies)
Discussion started by: findprakash
4 Replies

8. Shell Programming and Scripting

awk -help needed

hi, firstly, thank you all for helping me in previous posts. Here,I have a script with awk and a problem with in it as given below ********************************* parameter1=" $1" parameter2 = "$2" $script1 "parameter1" "parameter2" |\ { awk '{ ..... END{ ... (6 Replies)
Discussion started by: rider29
6 Replies

9. Shell Programming and Scripting

Help needed in writing awk script for xml source

Hi, i am not able to get an approach for converting xml file to flat file using awk programming. Can anyone help me out. The input xml is like this: <outer> <field1>one</field1> <field2>two</field2> <field3>three<Error Code=777 Description=12345/></field3> <field4>four</field4> </outer>... (2 Replies)
Discussion started by: naren_0101bits
2 Replies

10. Shell Programming and Scripting

Help with awk/shell script needed!

I have a shell script which reads a file named filelist.txt, containing a list of fully qualified filenames (with complete path), and then does some processing based on the file extension. In order to do the processing, I have to know the file extension, the filename without extension and just the... (3 Replies)
Discussion started by: inditopgun
3 Replies
Login or Register to Ask a Question