Help required with formatting


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Help required with formatting
# 1  
Old 05-05-2009
Help required with formatting

I would appreciate any help (sed / awk / perl) on the following question. I have the file in the following format. Note that the records are separated by the line that starts with the word "TRACE".I want the 5th and 6th values on the line starting with "TRACE" to be repeated down the file until the next record is hit (a line starting with the word TRACE). If this is my input file, then please have a look at the bottom i.e the output that I want using perl or awk.

INPUT
=======
TRACE mrjn05 6487 4922 358666.00 3154690.00 4 8
4 12068.6
12 12067.9
20 12066.7
28 12065.6
36 12064.7
44 12063.4
52 12062.1
60 12061.3
68 12060.9
76 12060.6
84 12057.9
92 12052.7
100 12052.1
TRACE mrjn05 6487 4923 358685.00 3154680.00 4 8
4 12068.6
12 12068
20 12066.9
28 12065.8
36 12064.7
44 12063.5
52 12062.2


OUTPUT
=======

TRACE mrjn05 6487 4922 358666.00 3154690.00 4 8
4 12068.6 358666.00 3154690.00
12 12067.9 358666.00 3154690.00
20 12066.7 358666.00 3154690.00
28 12065.6 358666.00 3154690.00
36 12064.7 358666.00 3154690.00
44 12063.4 358666.00 3154690.00
52 12062.1 358666.00 3154690.00
60 12061.3 358666.00 3154690.00
68 12060.9 358666.00 3154690.00
76 12060.6 358666.00 3154690.00
84 12057.9 358666.00 3154690.00
92 12052.7 358666.00 3154690.00
TRACE mrjn05 6487 4923 358685.00 3154680.00 4 8
4 12068.6 358685.00 3154680.00
12 12068 358685.00 3154680.00
20 12066.9 358685.00 3154680.00
28 12065.8 358685.00 3154680.00
36 12064.7 358685.00 3154680.00
44 12063.5 358685.00 3154680.00
52 12062.2 358685.00 3154680.00

Any help on this will be higly appreciated. The file is really huge (about 800 MB) and I am just a beginer. Please help.

Last edited by digipak; 05-05-2009 at 07:15 AM.. Reason: bad formatting
# 2  
Old 05-05-2009
Try this:

Code:
awk '/^TRACE/{s=$5 FS $6;print;next}{print $0, s}' file

# 3  
Old 05-05-2009
if you have Python, here's an alternative
Code:
for line in open("file"):
    line=line.strip()
    if "TRACE" in line:        
        four,five = line.split()[4:6]        
    else: print line.strip(),four,five

# 4  
Old 05-06-2009
Guys thanks a lot, I tried the awk way and it works fine. I have made a note of the python script, when I am bit more comfortable with the UNIX, God willing, I will try that out. Franklin, thanks a lot for your help. Higly appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting required with the output

i have a o/p from find command that needs to be formatted currently when i'm running find . -name "v.info" it is giving below o/p /o/a/b/c/v.info /o/a/b/c/d/v.info /o/aa/bb/cc/v.info /o/aa/bb/cc/dd/v.info my requirement is if v.info is coming under sub-directories it shul be... (15 Replies)
Discussion started by: nikhil jain
15 Replies

2. Shell Programming and Scripting

Awk help required for formatting digits.

Hi experts, I have two values in the file : For example : partcamt = 72.90 partdamt=27.9 I need to convert these values into 6 digits and ignore the "." sign so that the desired desired output is : total value= 0072000027900 Currently I am using the following code : ... (3 Replies)
Discussion started by: nua7
3 Replies

3. Shell Programming and Scripting

help formatting

I need to format a txt file and convert it in CSV. Any "future" column is separated by a newline. FROM: XS1 1.43294 0.0 XS2 1.21824 0.0 TO: XS1,XS2 (2 Replies)
Discussion started by: alfreale
2 Replies

4. Shell Programming and Scripting

formatting of df -k

Hello, I am developing a platform Independant tool that should work for all major unix flavors outlined in this forum(Solaris,Linux, AIX, HPUX, SCO,BSD) Therefore, in order to cover all types of user community, I have deliberately posted the same message on every forum. Please do not think... (9 Replies)
Discussion started by: darsh123
9 Replies

5. Shell Programming and Scripting

Formatting

Is there a way to make a 2 column output out of the following : 1 2 3 4 5 6 Output : 1 2 3 4 5 6 Thanks, Prasanna (3 Replies)
Discussion started by: prasanna1157
3 Replies

6. Shell Programming and Scripting

Help required with formatting in scripting

Hi Friends, I need to write a script which reads the file and prints them horizontally. For example, the file contains something like x1 x2 x3 x4 x5 my script reads this file as "for i in `cat filename`", but I need an output something like "config file = x1.ccfg,... (3 Replies)
Discussion started by: dineeshkg
3 Replies

7. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

8. Shell Programming and Scripting

formatting

I have file with different columns for ex. contents of file "txt" NAME AGE MARKS HARRY 23 89 TOM 12 67 BOB 23 11 and you see its not formatted.Now, I need the file "txt" to be formatted like COLUMN1 COLUMN2 COLUMN3 NAME AGE ... (3 Replies)
Discussion started by: vijay_0209
3 Replies

9. Shell Programming and Scripting

Formatting

I have next part of script: for i in $LIST do echo "`date +"%H:%M:%S"` Converting $i ..."; mysql -uroot some -sABe "ALTER TABLE $i ENGINE=$ENGINE"; done I want to get following output formatting: "OK" must be one under another :) ... (3 Replies)
Discussion started by: mirusnet
3 Replies

10. UNIX for Dummies Questions & Answers

formatting

Hi Again Guys , Please i installed linux RH 6.1 on Toshiba , 10G , RAM=128 , 600 MHZ . After i installed linux i got many error messages , seems it was not installed correctly , also when i finished installation it did not ask me for the 2nd installation CD , and when i logged as root , i... (5 Replies)
Discussion started by: tamemi
5 Replies
Login or Register to Ask a Question