Grep in file and print in the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep in file and print in the line
# 1  
Old 10-08-2013
Grep in file and print in the line

hi

Code:
# cat test.txt
Test
Date: 20131008                 1515
--------------------------------------------------------------------------------------------------------------
Saxx = Proc_m0_s13                       : 1640
Saxx = Proc_m0_s15                       : 1791
Saxx = Proc_m0_s17                       : 1644
Saxx = Proc_m0_s19                       : 1599
Saxx = Proc_m0_s21                       : 1715
Saxx = Proc_m0_s23                       : 1686
Saxx = Proc_m1_s1                        : 1632
Saxx = Proc_m1_s3                        : 1712
Saxx = Proc_m1_s5                        : 1574
Saxx = _SYSTEM                           : 14993
Saxx = Proc_m0_s13                       : 1864
Saxx = Proc_m0_s15                       : 1766
Saxx = Proc_m0_s17                       : 1739
Saxx = Proc_m0_s19                       : 1845
Saxx = Proc_m0_s21                       : 1941
Saxx = Proc_m0_s23                       : 1841
Saxx = Proc_m1_s1                        : 1780
Saxx = Proc_m1_s3                        : 1810
Saxx = Proc_m1_s5                        : 1720
Saxx = _SYSTEM                           : 16306

i want the output become like this :

Code:
20131008 1515 SaxxProc_m0_s13 1640
20131008 1515 SaxxProc_m0_s15 1791
20131008 1515 SaxxProc_m0_s17 1644
20131008 1515 SaxxProc_m0_s19 1599
20131008 1515 SaxxProc_m0_s21 1715
20131008 1515 SaxxProc_m0_s23 1686
20131008 1515 SaxxProc_m1_s1 1632
20131008 1515 SaxxProc_m1_s3 1712
20131008 1515 SaxxProc_m1_s5 1574
20131008 1515 Saxx_SYSTEM 14993
20131008 1515 SaxxProc_m0_s13 1864
20131008 1515 SaxxProc_m0_s15 1766
20131008 1515 SaxxProc_m0_s17 1739
20131008 1515 SaxxProc_m0_s19 1845
20131008 1515 SaxxProc_m0_s21 1941
20131008 1515 SaxxProc_m0_s23 1841
20131008 1515 SaxxProc_m1_s1 1780
20131008 1515 SaxxProc_m1_s3 1810
20131008 1515 SaxxProc_m1_s5 1720
20131008 1515 Saxx_SYSTEM 16306

Anybody can help?
I have try :

Code:
ts=`cat test.txt  | grep Date | awk '{print $2' '$3}'`; cat test.txt | grep Saxx| awk '{print '$ts' " "$1$3" "$5}'

But not working
# 2  
Old 10-08-2013
Try something like:
Code:
awk '/Date:/{c=$2 FS $3} NR>3{print c, $1 $2, $NF}' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 10-08-2013
Hi,

Let us say our data is in a file named get_exact_output.
Could you please use the following code.

Code:
awk '$NR==1 || /Date/ {next} sub(":",X) sub("=",Y) {print"20131008 1515 "$1 $2 " "$3}' get_exact_output

Output will bee as follows.

Code:
20131008 1515 SaxxProc_m0_s13 1640
20131008 1515 SaxxProc_m0_s15 1791
20131008 1515 SaxxProc_m0_s17 1644
20131008 1515 SaxxProc_m0_s19 1599
20131008 1515 SaxxProc_m0_s21 1715
20131008 1515 SaxxProc_m0_s23 1686
20131008 1515 SaxxProc_m1_s1 1632
20131008 1515 SaxxProc_m1_s3 1712
20131008 1515 SaxxProc_m1_s5 1574
20131008 1515 Saxx_SYSTEM 14993
20131008 1515 SaxxProc_m0_s13 1864
20131008 1515 SaxxProc_m0_s15 1766
20131008 1515 SaxxProc_m0_s17 1739
20131008 1515 SaxxProc_m0_s19 1845
20131008 1515 SaxxProc_m0_s21 1941
20131008 1515 SaxxProc_m0_s23 1841
20131008 1515 SaxxProc_m1_s1 1780
20131008 1515 SaxxProc_m1_s3 1810
20131008 1515 SaxxProc_m1_s5 1720
20131008 1515 Saxx_SYSTEM 16306



Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep echo awk print all output on one line

Hello, I've been trying to find the answer to this with Google and trying to browse the forums, but I haven't been able to come up with anything. If this has already been answered, please link me to the thread as I can't find it. I've been asked to write a script that pulls a list of our CPE... (51 Replies)
Discussion started by: rwalker
51 Replies

2. UNIX for Dummies Questions & Answers

Grep file and print value only if the following line doesnt contain value xxxx

Hi All, I have some large files which I would like to obtain some data from, I want to grep (or alturnative method) out certain values hut only if the folowing line doesnt contain a certain value. I will explain better below showing an example print of the data. NE : V0001 NE : V0002... (6 Replies)
Discussion started by: mutley2202
6 Replies

3. Shell Programming and Scripting

Grep or print each section of a file on one line with a separator

I can obtain information from itdt inventory command however it display as below, I'd like to print each entity on one line but seperated by : the file is something like and each section ends with Volume Tag Drive Address 256 Drive State ................... Normal ASC/ASCQ... (3 Replies)
Discussion started by: gefa
3 Replies

4. Shell Programming and Scripting

grep based on pattern in a line and print the column before that

$ cat file.log Message Number = : Sending message 10:50:16^|^reqhdr.dummyid^=^02^|^reqhdr.timezone^=^GMT+05:30^|^DUMMYREQUEST^=^BH||||||||||||||||||$BD|OL|C|V||DummyAcctNo|02||24/12/2011|ST_DDM|DDM||||||||reqUUID110612105016$BT||||||||||||||||||$] Length I have the above line in the... (4 Replies)
Discussion started by: kalidass
4 Replies

5. Shell Programming and Scripting

grep a string and print strings on that line

i have a file like below ABS 12234 A C 12G CFY 23865 A C 34D i want to grep "A C" then print ABS 12G 12234 CFY 34D 23865 Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

6. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

7. UNIX for Dummies Questions & Answers

grep N lines after match and then print them on 1 line each

Hello I have a silly question. I need to grep a match in text file and then print 5 lines after it. grep -A 5 .... do it. OK The next thing I can not handle is I need each output to be on 1 line match line2 line3 line4 line5 match line2 line3 line4 line5 etc.. I will really... (10 Replies)
Discussion started by: alekkz
10 Replies

8. Shell Programming and Scripting

grep N lines after match and then print them on 1 line each

Hello I need some help with this job. file.txt ----- cut ---- TARGET 13/11/08 20:43:21 POINT 1 MOVE 8 772102y64312417771 TARGET 13/11/08 21:10:01 POINT 2 MOVE 5 731623jjd12njhd ----- cut ---- this is the example. i need to grep for the word TARGET and print next 4 lines like... (1 Reply)
Discussion started by: alekkz
1 Replies

9. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

10. Shell Programming and Scripting

print a line containing word in a column using grep

hi, how to print a row which contains a perticular word in its third column using grep, cut, or any thing else. thanks (2 Replies)
Discussion started by: useless79
2 Replies
Login or Register to Ask a Question