remove newline between two string with sed command in unix shellscript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove newline between two string with sed command in unix shellscript
# 1  
Old 02-21-2011
Debian remove newline between two string with sed command in unix shellscript

I have a file (test.dat) which contains data like this
Code:
459|199811047|a |b |shan
kar|ooty|
460|199811047|a |bv |gur
u|cbe|

but I need it like:
Code:
459|199811047|a |b |shankar|ooty|
460|199811047|a |b |guru|cbe|

While reading the data from this file, I don't want to remove newline from the end of each record. I just want to remove the \n between two string (like:shankar) inside the pipe symbol.

actually inside the unix my dat file... consist of 500 character.. so the first 300 character appear in the first line and got break(newline)for the next 200 character... but the 500 should be treated like single line.. so am trying to append the characters which has got break because of newline. am using | as delimiter..plz help me... with sed command..

Last edited by Franklin52; 02-22-2011 at 03:01 AM.. Reason: Please use code tags
# 2  
Old 02-21-2011
Code:
perl -p0e 's/(\w)\n(\w)/\1\2/g' file

# 3  
Old 02-21-2011
is there any other command with the help of sed.. because perl command not supported in my unix.. if u dont mind plz help me am new to this.
# 4  
Old 02-21-2011
Code:
paste -d'\0' - - < input_file

# 5  
Old 02-21-2011
Try:
Code:
sed 'N;s/\n//' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed to remove newline chars based on pattern mis-match

Greetings Experts, I am in AIX; I have a file generated through awk after processing the input files. Now I need to replace or remove the new-line characters on all lines that doesn't have a ; which is the last character on the line. I tried to use sed 's/\n/ /g' After checking through the... (6 Replies)
Discussion started by: chill3chee
6 Replies

2. Shell Programming and Scripting

Shellscript command to remove files starting with a certain string, and older than 3 days

Hi All, Need help in identifying a shellscript command to remove all files on a server directory, starting with a certain prefix and also older than 3 days. That means files created with that prefix, today or yesterday, shouldn't be removed. Thanks, Dev (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

3. Shell Programming and Scripting

Remove last occurrence of character (_) and rest of the string in UNIX (sed)

Hi I need help on this ..!! Input : xx_abc_regA xx_def_regB xx_qwe_regC Now i required the output as the below abc def qwe Need to remove last occurrence of character (_) and rest of the string in Unix (sed). Thanks in Advance ..!!! -Nallachand (3 Replies)
Discussion started by: Nallachand
3 Replies

4. Linux

Remove newline in middle of string

my file input is with tab as delimiter, and in every line, there would be a skip of line with an unexcepted newline breaker. I'd like to remove this \n and put the information in the same line. INPUT a1 b1b2 c1 c2 d1 a2 b3 c3 d4 OUTPUT a1 b1b2 c1c2 ... (9 Replies)
Discussion started by: kinkichin
9 Replies

5. Shell Programming and Scripting

ShellScript to Remove Newline in ouput.csv

Hi friends, I am running one SQL though .sh file and in output I am seeing newline whevnever There is a new line in column. I WANT TO REMOVE NEWLINE IN OUTPUT FILE. Present out put in Column: ------------------------- Hi How Are You. Required output in Column: ------------- Hi How... (4 Replies)
Discussion started by: crmsachin
4 Replies

6. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

7. Shell Programming and Scripting

any savant ? using AWK/SED to remove newline character between two strings : conditional removal

I'd like to remove (do a pattern or precise replacement - this I can handle in SED using Regex ) ---AFTER THE 1ST Occurrence ( i.e. on the 2nd occurrence - from the 2nd to fourth occurance ) of a specific string : type 1 -- After the 1st occurrence of 1 string1 till the 1st occurrence of... (4 Replies)
Discussion started by: sieger007
4 Replies

8. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

9. Shell Programming and Scripting

SED: how to remove newline after pattern?

Hi, I have the following XML not well-indented code: <hallo >this is a line </hallo> So I need to remove the newline. This syntax finds what I need to correct, but I don't know how to remove the newline after my pattern: sed 's/<.*$/&/' How can I subtract the newline after my... (1 Reply)
Discussion started by: nico.ben
1 Replies

10. Shell Programming and Scripting

sed ksh remove newline between 2 containers

If we assume that each line between the {} container is an XML document then What I want to remove the newline character from all lines within each container to have one XMDL document per line I wrote a bit of sed after trawling the web: e.g. #!/bin/sed -nf H /}/ { x s/\n//g p... (3 Replies)
Discussion started by: JamesJSC
3 Replies
Login or Register to Ask a Question