How to remove line break character in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove line break character in a file
# 1  
Old 04-15-2011
How to remove line break character in a file

Hi,
we are trying to process a csv file,in which we are getting data with line breaks.How to remove the line break character in the file?
when i try to print the line break charcter using od -c,it gives as '\n' character for both line break and line feed.

Please provide your valuable suggestion to resolve this.
# 2  
Old 04-15-2011
Please give an example how looks your input file and how it should be output so people can provide a more accurate help
# 3  
Old 04-15-2011
Hi,
Please find the sample data
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie

actual data should be
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8Perushtitza",,4002,,3/11/2009,3/11/2009,Christie,Christie
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8Perushtitza",,4002,,3/11/2009,3/11/2009,Christie,Christie
# 4  
Old 04-15-2011
Code:
sed 'N;s/\n//' inputfile

---------- Post updated at 01:56 AM ---------- Previous update was at 01:54 AM ----------

Also

Code:
sed '/^Bulgaria/N;s/\n//' inputfile

# 5  
Old 04-15-2011
Quote:
Originally Posted by cnraja
when i try to print the line break charcter using od -c,it gives as '\n' character for both line break and line feed.
If by line break you mean a newline, \n, and by line feed you mean a form feed, \f, then if the following does not show \f followed by \n, your od (or printf) has a serious bug.

Code:
$ printf '\f\n' | od -c
0000000   \f  \n
0000002

Regards,
Alister
# 6  
Old 04-15-2011
Hi,
Sample file possess Bulgaria in it,however in real scenario there might be some other name coming in terms of Bulgaria
# 7  
Old 04-15-2011
Code:
$ cat tst
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Croatia,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Croatia,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Croatia,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Romania,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Romania,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Serbia,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie

Code:
$ awk '/Bulgaria|Romania/{x=$0;getline;sub($0,x $0)}1' tst
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza",,4002,,3/11/2009,3/11/2009,Christie,Christie
Bulgaria,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza",,4002,,3/11/2009,3/11/2009,Christie,Christie
Croatia,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Croatia,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Croatia,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie
Romania,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza",,4002,,3/11/2009,3/11/2009,Christie,Christie
Romania,CC,MallPlovdiv,Plovdiv,CCBPLO,2,CCBPLO2,"8 Perushtitza",,4002,,3/11/2009,3/11/2009,Christie,Christie
Serbia,CC,MallPlovdiv,Plovdiv,CCBPLO,1,CCBPLO1,"8 Perushtitza
",,4002,,3/11/2009,3/11/2009,Christie,Christie

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove line break at specific position

Hi, I need to remove line breaks from a file, but only the ones at specific position. Input file: this is ok this line is divided at posit ion 30. The same as this one, also position 30 the rest of lines are ok with different lengths The longest ones are always s plitted at same... (15 Replies)
Discussion started by: qranumo
15 Replies

2. UNIX for Dummies Questions & Answers

How to remove $ or new line character in a file?

Hi All, Could any one suggest how to remove $ symbol in a text file when i am opening in vi editor. Scenario; For example iam having a file name aaa.txt the data inside the file is like sample name when i am opening in vi editor The same file resembles like below when i am... (1 Reply)
Discussion started by: Chandru_Raj
1 Replies

3. Shell Programming and Scripting

How to Remove comma as last character in end of last line of file?

how to Remove comma as last charector in end of last line of file: example: input file --------------- aaaaaa, bbbbbb, cccc, 12345, ____________ output file : ----------- aaaaaa, bbbbbb, (6 Replies)
Discussion started by: RahulJoshi
6 Replies

4. Shell Programming and Scripting

Remove the last character (,) for every line in a file

Good afternoon: im working wih 2 files to find differences and use the cmp command cmp file1 file2 file1 file2 are are diifferent char 302 line1 i found what the difference is with the sed command and that is the file1 at the end of every line has a (,) (comma) character. i.e sed -n... (4 Replies)
Discussion started by: alexcol
4 Replies

5. Shell Programming and Scripting

How to remove new line character at end of file.

I need to remove new line character from end of file. Suppose here are content. a|b|c|d|r a|b|c|d|r a|b|c|d|r <new line> that means file contains 4 lines but data is there in 3 lines. so I want that only 3 lines should be there in file. Please help (20 Replies)
Discussion started by: varun940
20 Replies

6. UNIX for Dummies Questions & Answers

Remove Line Break VI

I'm trying to make a script that says echo This is the date: I did this echo This is the date: date and it worked. But I need them both on the same line. And putting date on the echo line doesn't work. Is there a way to do so? (1 Reply)
Discussion started by: bbowers
1 Replies

7. Shell Programming and Scripting

Help to remove line break

My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1.Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra... (4 Replies)
Discussion started by: cnraja
4 Replies

8. Shell Programming and Scripting

How to remove line break in a csv file

Hi Experts, My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1, Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra... (6 Replies)
Discussion started by: cnraja
6 Replies

9. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

10. Shell Programming and Scripting

Remove Line Break

Dear all, Please advise what approach can remove all line break from a text file? e.g. Source file: A B C Target file: A, B, C Thanks, Rock (5 Replies)
Discussion started by: Rock
5 Replies
Login or Register to Ask a Question