How to remove line break in a csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove line break in a csv file
# 1  
Old 01-12-2011
Question 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:
Code:
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:
Code:
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

Please provide solution to this.

Last edited by fpmurphy; 01-12-2011 at 12:54 PM.. Reason: Code tags please!!
# 2  
Old 01-12-2011
try with sed..
Code:
sed '/,$/{N;s/\n/ /}' inputfile > outfile

# 3  
Old 01-12-2011
Hi Michael,
I am getting this error
sed: Function /,$/{N;s/\n/ /} cannot be parsed.

---------- Post updated at 12:17 PM ---------- Previous update was at 11:57 AM ----------

Hi Michael,
I am getting this error
sed: Function /,$/{N;s/\n/ /} cannot be parsed. be parsed.
# 4  
Old 01-13-2011
I do not have access to unix box right now, so would not be able to test. Can you post your execution statement..?

---------- Post updated 01-13-11 at 10:26 AM ---------- Previous update was 01-12-11 at 11:06 PM ----------

The above sed command works fine im my linux machine.To find the root cause post your execution line,OS and the sed version. However try the below awk
Code:
awk '/,$/{getline x}{print $0 x}' inputfile > outfile

This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 01-13-2011
Quote:
Originally Posted by michaelrozar17
I do not have access to unix box right now, so would not be able to test. Can you post your execution statement..?

---------- Post updated 01-13-11 at 10:26 AM ---------- Previous update was 01-12-11 at 11:06 PM ----------

The above sed command works fine im my linux machine.To find the root cause post your execution line,OS and the sed version. However try the below awk
Code:
awk '/,$/{getline x}{print $0 x}' inputfile > outfile

Does {getline x} get the next record from the curruent record?
# 6  
Old 01-13-2011
Yes it gets the next line only when the current line ends with a ,
# 7  
Old 01-13-2011
Quote:
Originally Posted by michaelrozar17
Yes it gets the next line only when the current line ends with a ,
Thank you! I learn something new everyday!
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. Shell Programming and Scripting

Break Column nth in a CSV file into two

Hi Guys, Need help with logic to break Column nth in a CSV file into two for e.g Refer below the second column as the nth column "abcd","","type/beta-version" need output in a following format "abcd","/place/asia/india/mumbai","/product/sw/tomcat","type/beta-version" ... (5 Replies)
Discussion started by: awk-admirer
5 Replies

3. Shell Programming and Scripting

Need help with awk statement to break nth column in csv file into 3 separate columns

Hello Members, I have a csv file in the format below. Need help with awk statement to break nth column into 3 separate columns and export the changes to new file. input file --> file.csv cat file.csv|less "product/fruit/mango","location/asia/india","type/alphonso" need output in... (2 Replies)
Discussion started by: awk-admirer
2 Replies

4. Shell Programming and Scripting

Remove line breaks in csv file using shell script

Hi All, I've a csv file in which the record is getting break into 1 line or more than one line. I want to combine those splits into one line and remove the unwanted character existing in the record i.e. double quote symbol ("). The line gets break only when the record contains double... (4 Replies)
Discussion started by: rajak.net
4 Replies

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

6. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

7. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

8. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: cnraja
6 Replies

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

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