Need helpl in scripting read 2 lines and paste to one single line.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need helpl in scripting read 2 lines and paste to one single line.
# 1  
Old 04-20-2009
Need helpl in scripting read 2 lines and paste to one single line.

Hi All,

I need to create script which will accept one file as i/p and give me o/p file described as below.

1) i/p log file named abc.log contents several lines but i am interested in lines like below.

#FILE..... /oracle/XYZ/sapdata1/undo_7/undo.data7
#SAVED.... BACKINTID001

2) o/p file should be such that it should look like below.

BACKINTID001 /oracle/XYZ/sapdata1/undo_7/undo.data7 /oracle/ABC/sapdata1/undo_7

Even if i get till below its ok
BACKINTID001 /oracle/XYZ/sapdata1/undo_7/undo.data7

I am currently using below to take o/p and paste in excel and use excel formatting to get required o/p

grep "#FILE" abc.log| awk '{print $2}'
grep "#SAVED" abc.log | awk '{print $2}'

Please let me how this can be done..
# 2  
Old 04-20-2009
paste a sample input file and expected output file plz.


cheers,
Devaraj Takhellambam
# 3  
Old 04-20-2009
abc.log file looks like below..
----------------------------------------------------------------
#FILE..... /oracle/XYZ/sapdata1/undo_7/undo.data7
#SAVED.... BACKINTID001
BR0280I BRBACKUP time stamp: 2009-04-07 08.37.40
#FILE..... /oracle/XYZ/sapdata1/undo_8/undo.data8
#SAVED.... BACKINTID002
BR0280I BRBACKUP time stamp: 2009-04-07 08.37.42
#FILE..... /oracle/XYZ/sapdata2/undo_9/undo.data9
#SAVED.... BACKINTID003
----------------------------------------------------------------

o/p file should be as.

BACKINTID001 /oracle/XYZ/sapdata1/undo_7/undo.data7 /oracle/XYZ/sapdata1/undo_7
BACKINTID002 /oracle/XYZ/sapdata1/undo_8/undo.data8 /oracle/XYZ/sapdata1/undo_8
BACKINTID003 /oracle/XYZ/sapdata2/undo_9/undo.data9 /oracle/XYZ/sapdata2/undo_9


or as

BACKINTID001 /oracle/XYZ/sapdata1/undo_7/undo.data7
BACKINTID002 /oracle/XYZ/sapdata1/undo_8/undo.data8
BACKINTID003 /oracle/XYZ/sapdata2/undo_9/undo.data9

I can get required o/p by using below commands

grep "#FILE" abc.log| awk '{print $2}'
grep "#SAVED" abc.log | awk '{print $2}'

but that needs to be formatted as per my o/p requirements.
# 4  
Old 04-20-2009
Code:
awk '{ if( $1 ~ /^#FILE/) {old=$2}
         if ($1 ~ /^#SAVED/) {print $2, old} }' inputfilename > newfilename

# 5  
Old 04-20-2009
Wow thanks "jim mcnamara" it worked really well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Paste 2 single column files to a single file

Hi, I have 2 csv/txt files with single columns. I am trying to merge them using paste, but its not working.. output3.csv: flowerbomb everlon-jewelry sofft steve-madden dolce-gabbana-watchoutput2.csv: http://www1.abc.com/cms/slp/2/Flowerbomb http://www1.abc.com/cms/slp/2/Everlon-Jewelry... (5 Replies)
Discussion started by: ajayakunuri
5 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

how to read multi line characters in a single column

Hi, I have file in which fields are pipe (|) separated and the record separator is new line (\n). But sometime I am getting a field value which is spread across multiple line. Basically I am getting a file from another system in the below format and needs to process the file and load data into a... (3 Replies)
Discussion started by: satyaatcgi
3 Replies

4. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

5. Shell Programming and Scripting

Read duplicate column, then generate a single line

Dear experts, How to generate the result listed below ? Input file: col1col2col3Aname1size1Aname2size2Aname3size1Bname4size3Bname5size5Cname6size8Cname7size6Cname8size9Cname9size11Cname10size16 What I want is: Aname1, size1name2, size2name3, size1Bname4,size3name5, size5Cname6,... (1 Reply)
Discussion started by: tojzz
1 Replies

6. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

7. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

8. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

9. Shell Programming and Scripting

paste each 10 lines of single column to several column

Hi, I need to paste each 10 lines of single column to several columns. Please, can anyone tell me how to write in awk? Input File: 22 34 36 12 17 19 15 11 89 99 56 38 29 (4 Replies)
Discussion started by: nica
4 Replies

10. Shell Programming and Scripting

Read line with a single key press...

I would really like to have a script that will accept the key press from the user with out having to press the enter key afterwards. i.e. echo "Press Y to print \c" read YesNo At this point the user has to press the enter key to continue. Is there a way to accept the key press from the... (3 Replies)
Discussion started by: jagannatha
3 Replies
Login or Register to Ask a Question