Combine line before the pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine line before the pattern
# 1  
Old 10-05-2010
Combine line before the pattern

Hi,

I am not very familiar with sed and awk and i have a huge file to process which is impossible to do manually. I want to print out beginning from "Network" until end of line only (excluding the Version). AND. the decription to be all in one line.

File:
Code:
Version: 2.0          Network: xxx yyy
Description: this is just a sample
file for this testing
today
Version: 2.0          Network: testing 123
Description: another testing
Version: 2.0          Network: abc-12333
Description: another testing again
and again

Output:
Code:
Network: xxx yyy
Description: this is just a sample file for this testing today
Network: testing 123
Description: another testing
Network: abc-12333
Description: another testing again and again

thanks so much for checking on it.
# 2  
Old 10-05-2010
Code:
sed '
s/.*Network:/Network:/
t next
d
:next
N
'

This User Gave Thanks to DGPickett For This Post:
# 3  
Old 10-05-2010
Code:
awk -vORS=" " '/^Version/{sub(".*Net","Net");printf "\n"$0"\n";next}1;END{printf "\n"}' file

# 4  
Old 10-05-2010
Quote:
Originally Posted by DGPickett
Code:
sed '
s/.*Network:/Network:/
t next
d
:next
N
'

It didnt combine the "Description" part.

Last edited by The One; 10-05-2010 at 02:05 PM..
# 5  
Old 10-05-2010
Code:
awk  -F'  ' '/Version/{print ((NR==1)?x:RS)$NF;next}{printf ((/Description/)?x:OFS)$0}' file


Last edited by danmero; 10-05-2010 at 02:37 PM..
# 6  
Old 10-05-2010
Quote:
Originally Posted by The One
It didnt combine the "Description" part.
Did you try my code?
# 7  
Old 10-05-2010
Quote:
Originally Posted by bartus11
Did you try my code?
Works but add a new line at the beginning.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

4. Shell Programming and Scripting

Combine multiline to one line till a blank line

Hello, I have a file as :- ABC DEF GHI JKL <BlankLine> MNO PQR STU VWX <BlankLine> YZA I need it as below:- ABCDEFGHIJKL; MNOPQRSTUVWX; (3 Replies)
Discussion started by: jassi10781
3 Replies

5. Shell Programming and Scripting

Combine 3 files based on a pattern

HI, I have 3 files that contain the following information (sql output from Oracle database stored in a txt file): File1.txt : alter table "SYS"."INT_COST_PRICE" enable row movement; alter table "SYS"."INT_SOH" enable row movement; alter table "SYSMAN"."XX_ACI_SKURTP" enable row movement;... (6 Replies)
Discussion started by: rparavastu
6 Replies

6. Shell Programming and Scripting

Combine 4 awk pattern count statements into 1

Hello fellow awkers, I am trying to combine the following awk statements into 1 so that the results are more accurate: awk '/\=\+/ { count++ } END { print count}' filename awk '/\=\?/ { count++ } END { print count}' filename awk '/\=\-/ { count++ } END { print count}' filename awk... (8 Replies)
Discussion started by: ux4me
8 Replies

7. Shell Programming and Scripting

Search Pattern and combine into single file

Hi Experts Please help me out with the following thing: 2 files and want the output file: {No for using FOR loop because I got 22 million lines} Tried that "It processes only 8000 records per hour" I need a faster way out !!! FileA: 9051 9052 9053 9054 9055 9056 9057 9058 9059 ... (5 Replies)
Discussion started by: navkanwal
5 Replies

8. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

9. Shell Programming and Scripting

How to combine lines within range of pattern

I've a file say having line 1 line 2 (NP line 3 line 4 line 5) line 6 I want to combine lines starting from (NP and ending with ) then it will look like line 1 line 2 (NP line3 line4 line5) line 6 I tried using sed '/(NP/,/)$/ s/\n/ /' but it's not working. Any help please? ... (8 Replies)
Discussion started by: neg
8 Replies

10. Shell Programming and Scripting

Combine the lines based on particular pattern

Hi, I've a weird problem to be solved. Assume i have a file like this: 1. <timestamp> UID: 12345 <junk> DevID: V123 2. <timestamp>DevID: V123 <junk> DuID: VP 3. ... 4. .... 5. <timestamp> UID: 789 <junk> DevID: S456 6. <timestamp>DevID: S456 <junk> DuID: VP.... 7. ..... Say if i... (3 Replies)
Discussion started by: VenkataPrasad
3 Replies
Login or Register to Ask a Question