Concatenate 2 rows into 1 row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenate 2 rows into 1 row
# 1  
Old 03-10-2005
Question Concatenate 2 rows into 1 row

I need to search a file for two values (valueA & valueB). ValueA will be on a different row than valueB, and concatenate the two together on the same row of my output.

Example: search input file for strings "node" and "OS", combine the two results into one row

input
node A
text
text
OS B
text
node AA
text
text
OS BB


Disired output

node A OS B
node AA OS BB

thanks!!!!
# 2  
Old 03-10-2005
im sure there is better way to do this but this is what i came up with

grep '^(nod|OS)' filename | sed '$!N;s/\n/ /'


[im using windows, parentheses dont seem to work]

Last edited by tanku; 03-10-2005 at 07:00 PM..
# 3  
Old 03-10-2005
Quote:
Originally Posted by tanku
[im using windows, parentheses dont seem to work]
Use egrep
Code:
egrep '^(nod|OS)' filename | sed '$!N;s/\n/ /'

Here's another way, using awk...
Code:
awk '/node/ {printf("%s ",$0)} /OS/ {printf("%s\n",$0)}' filename

Cheers
ZB
# 4  
Old 03-11-2005
thanks for the tip.. i am using cygwin now . it looks like unix.
# 5  
Old 03-11-2005
Thanks Zazzybob....it worked perfectly!!!

Good day mate
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

2. Shell Programming and Scripting

Concatenate rows and redefine range

I'm trying to find a way to concatenate consecutive rows (key is column $1 and $2) if column $5 an $6 are integers and redefine ranges in columns $3&$4 and $5&$6 Unfortunately I'm still learning the very basics so I cannot figure a way of doing this with awk. Input file 15 30 21 21 25.0... (11 Replies)
Discussion started by: alex2005
11 Replies

3. Shell Programming and Scripting

Concatenate broken rows

I need to concatenate the rows that are broken (because of carriage return and line feed) in unix. Input 123|456|789|"" 987|786|"GRT "|"" 3455|896|654|456|"" 457|234|"RT"|"PR TY"|"" Output 123|456|789|"" 987|786|"GRT"|"" 3455|896|654|456|"" 457|234|"RT"|"PRTY"|"" (16 Replies)
Discussion started by: meet_calramz
16 Replies

4. UNIX for Dummies Questions & Answers

Concatenate column data, grouped by row info

Hello, I have data which looks like: 1 2 3 a x 0 0 a 0 p 0 a 0 0 0 b 0 b c b a 0 0 b 0 0 0 c q 0 s c 0 r 0 I would like to concatenate each of the column data, grouped by the row values, i.e. my... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

5. Shell Programming and Scripting

Need help to read rows from one file and concatenate to another

Hi guys; TBH I am an absolute novice, when it comes to scripting; I do have an idea of the basic commands... Here is my problem; I have a flatfile 'A' containing a single column with multiple rows. I have to create a script which will use 'A' as input and then output a string in in the... (6 Replies)
Discussion started by: carlos_anubis
6 Replies

6. UNIX for Dummies Questions & Answers

Read rows from source file and concatenate output

Hi guys; TBH I am an absolute novice, when it comes to scripting; I do have an idea of the basic commands... Here is my problem; I have a flatfile 'A' containing a single column with multiple rows. I have to create a script which will use 'A' as input and then output a string in in the... (0 Replies)
Discussion started by: carlos_anubis
0 Replies

7. Shell Programming and Scripting

Concatenate some of the rows...

i have a file as below and i need to load it into oracle. The problem is, some of the rows are in 2 lines. 123456_PosWlist ----- ----- IN 0/0 123456_PosWListRpt ----- ----- IN 0/0 123456_PosWListCSV ----- -----... (7 Replies)
Discussion started by: Amit.Sagpariya
7 Replies

8. Shell Programming and Scripting

concatenate two files with different No of rows

need a shell which perform following function file 1 ( every time new data comes) 1212 2323 3434 4545 5656 . . . . file 2 (fixed line) update bc_tbl set aix=data , bix=back where cix=U and serial=; now when i execute shell it will concatinate file 1, file 2 & make file 3 as... (3 Replies)
Discussion started by: The_Archer
3 Replies

9. Shell Programming and Scripting

How to concatenate a string in every row data of a file??

Please look into the example. My source file is like, 00,57,3,2008-07-24 06:30:06 10,1,8025171,"1M00",17907023,2008-07-23 18:16:58 10,2,8025171,"1M00",17907023,2008-07-23 18:17:01 99,184 What should i do if i want output like... hello,00,57,3,2008-07-24 06:30:06... (7 Replies)
Discussion started by: pkumar3
7 Replies

10. Shell Programming and Scripting

Concatenate rows in to 2 files

I have 2 files FILEA 1232342 1232342 2344767 4576823 2325642 FILEB 3472328 2347248 1237123 1232344 8787890 I want the output to go into a 3rd file and look like: FILEC 1232342 3472328 (1 Reply)
Discussion started by: unxusr123
1 Replies
Login or Register to Ask a Question