Combine 2 line with space issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine 2 line with space issue
# 1  
Old 07-21-2011
Combine 2 line with space issue

Hello all,
i am new to linux , and please need your help and suggestion on....
when vi 1.txt :set list, it looks like
$ is displaying the end of line

Filter: vlan1-BUM-1M $
BUM-1M 0 0$
Filter: vlan2-BUM-1M $
BUM-1M 0 0$
Filter: vlan3-BUM-1M $
BUM-1M 0 0$
Filter: vlan4-BUM-1M $
Filter: vlan5-BUM-1M $
Filter: vlan6-BUM-1M $
BUM-1M 0 0$

how i can use the awk or... to change the output to
Filter: vlan1-BUM-1M BUM-1M 0 0
Filter: vlan2-BUM-1M BUM-1M 0 0
Filter: vlan3-BUM-1M BUM-1M 0 0
Filter: vlan6-BUM-1M BUM-1M 0 0
while vlan 4 and vlan5 is not require to display as they does not follow with "BUM"

actually there was a post from me before..
https://www.unix.com/shell-programmin...e-2-lines.html
it works perfect if i copy and paste from the putty.
but if i run on the bash script... the output was only showing
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0

i try some sed with erase some whitespace but.....
thanks a lot.
# 2  
Old 07-21-2011
Code:
sed -n '                              
/^Filter/h;                   
/^BUM/H;x;s/\n/ /p' INPUTFILE

Better:

Code:
sed -n '                              
/^Filter/h                   
/^BUM/H;x;s/\n//p' INPUTFILE


Last edited by yazu; 07-21-2011 at 01:30 PM.. Reason: Better
# 3  
Old 07-21-2011
The full story is i use a expect script to telnet to a network equipment, and grep out some of the stuff to become 1.txt.

however i try the sed recommended by you, but still getting , what was my mistake will be?

BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
BUM-1M 0 0
# 4  
Old 07-22-2011
Check what newline chars you got (DOS or Unix?).
# 5  
Old 07-22-2011
Yazu

i just checked, 101.txt file is manually copy and paste from putty, and works fine.
while 1.txt is a long whitespace before the $ .

thanks a lot.

vi 101.txt :set list
Filter: vlan429-BUM-1M$
BUM-1M 0 0$

vi 1.txt :set list
Filter: vlan1-BUM-1M (a long whitespace...) $
BUM-1M 0 0$
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine incrimental line

hi guys, i am writing a bash script.. that produce output some thing like this: road 100 300 500 road 100 300 500 road 100 300 500 road 100 300 500 street 400 200 700 street 400 200 700 path 200 100 900 i would like to combine all the entries that having the same but incremental (not... (12 Replies)
Discussion started by: pedot
12 Replies

2. 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

3. 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

4. Shell Programming and Scripting

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: Version: 2.0 Network: xxx... (9 Replies)
Discussion started by: The One
9 Replies

5. Shell Programming and Scripting

Stripping out more than a space from a line, but keep single space.

Hi all, Is there a way to perform the above, I am trying to strip out more than one space from a line, but keep the single space. See below output example. My Name is test test2 test3 test4 test5 My Name is test test2 test3 test4 test5 Please note that the lines would contain... (7 Replies)
Discussion started by: eo29
7 Replies

6. UNIX for Dummies Questions & Answers

What is the command use to combine line using sed

Hi all, What is the sed command use to combine line? Example: Below is an output after extracted from few commands aaa bbb ccc ddd eee fff ggg and i would like to combine all the line as shown below, aaa,bbb,ccc,ddd,eee,fff (5 Replies)
Discussion started by: 793589
5 Replies

7. UNIX for Dummies Questions & Answers

combine files line by line

Hi all, I once knew of a simple unix command to do this, but I can't remember it and I can't find it by searching. I have two files. ### FILE A #### A1 A2 A3 A4 A5 ### FILE B #### B1 B2 B3 B4 B5 (2 Replies)
Discussion started by: Digby
2 Replies

8. UNIX for Dummies Questions & Answers

Combine fields and eliminate white space

Good Morning, Newbie here. Could someone help with shell scripting that will enable me to combine 2 fields into one eliminating the white space. The fields are fixed but the data of course varies. For example: First Name: "George " 20 positions" Last Name: "Washington " 30 positions" I need... (2 Replies)
Discussion started by: ski
2 Replies

9. Shell Programming and Scripting

Combine output on same line

I am trying to get some data from a file and print it on the same line. I have a script that gets the date/time and calculates a DB query call time and sends to a file. I need to take this file and send it in a xcel like format with multiple data columns. example output file (fndbq.out) ... (3 Replies)
Discussion started by: theninja
3 Replies

10. Shell Programming and Scripting

Combine reports and append a line between each

I am new to Unix and have tried to write a ksh script to do the following without success: I have several reports in a directory (report1, report2, report3, etc). I would like to combine all of these reports into one file (REPORTS). I would like to append *** End of Report *** to each report so... (2 Replies)
Discussion started by: ldevito1
2 Replies
Login or Register to Ask a Question