help to replace extra new line characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help to replace extra new line characters
# 1  
Old 08-04-2008
help to replace extra new line characters

Hi
my file data is like below

ramu,sony,"raju \n ravi \n ramya" \n
ravi,sarah,"sowmya \n sorry s\ sangam" \n

i want replace new line characters in between double coats with sinhle space.

for example
cat input_file

ramu,sony,"raju
ravi
ramya"
ravi,sarah,"sowmya
sorry
sangam"

which i dont want. i want out put like below.i want replace newline s in between double quoates.

ramu,sony,"raju ravi ramya"
ravi,sarah,"sowmya sorry sangam"

any body can help either perl script or any other script
# 2  
Old 08-04-2008
Tools Would this work for you?

Code:
> cat new_lines | sed 's/" /" ~/' | tr "\n" " " | tr "~" "\n"

new_lines is your input file
wherever it sees a " -- replace with " ~
get rid of all new-lines
replace the ~ with a new-line
# 3  
Old 08-04-2008
Hi

it is replacing all new lines including out side coats.like below

ramu,sony,"raju ravi ramya" ravi,sarah,"sowmya sorry sangam"

but i want out put like below.

ramu,sony,"raju ravi ramya"
ravi,sarah,"sowmya sorry sangam"

sample data file is

ramu,sony,"raju \n ravi \n ramya" \n
ravi,sarah,"sowmya \n sorry s\ sangam" \n
# 4  
Old 08-04-2008
Question

this part - I improved a little - appears to work for me
Code:
sed 's/" /" ~/' | tr -d "\n" | tr -s " " | tr "~" "\n"

In your input file, it is ramya then space the "
that is what I was coding for
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need to replace new line characters in a huge file

Hi , I would like to replace new line characters(\n) in a huge file of about 2 million records . I tried this one (:%s/\n//g) but it's hanging there and no result. Does this command do not work if the file is big. Please let me know if you have any other options Regards Raj (1 Reply)
Discussion started by: rajeevm
1 Replies

2. UNIX for Dummies Questions & Answers

Replace extra Characters

The result of following command give me output which i further need to make some cosmetic change. grep -E "ERROR.*Session" wf_Load_25.log | awk '{print $14}' Output: : Expected Output: s_Load_XMLFile_Into_HashCustLoan_25 Please help, i am using bash (2 Replies)
Discussion started by: Ariean
2 Replies

3. Shell Programming and Scripting

sed replace range of characters in each line

Hi, I'm trying to replace a range of characters by their position in each line by spaces. I need to replace characters 95 to 145 by spaces in each line. i tried below but it doesn't work sed -r "s/^(.{94})(.{51})/\ /" inputfile.txt > outputfile.txt can someone please help me... (3 Replies)
Discussion started by: Kevin Tivoli
3 Replies

4. UNIX for Dummies Questions & Answers

Bash: using SED, trying to replace some characters except first or last line

Hi, I require to replace 2 items: 1. replace start of all lines in a file with ' except the first line 2. replace end of all lines in a file with '||chr( except last line I am able to do the entire file using sed -e s/^/\'/g -e s/$/\'\|\|chr\(/g "$file" > newfile.txt but am not yet... (3 Replies)
Discussion started by: Chella15
3 Replies

5. Shell Programming and Scripting

Bash: using SED, trying to replace some characters except first or last line

Hi, I require to replace 2 items: 1. replace start of all lines in a file with ' except the first line 2. replace end of all lines in a file with '||chr( except last line I am able to do the entire file using sed -e s/^/\'/g -e s/$/\'\|\|chr\(/g "$file" > newfile.txt but am not yet able... (0 Replies)
Discussion started by: Chella15
0 Replies

6. UNIX for Dummies Questions & Answers

Removing extra new line characters

Hello, I have a text file that looks like: ABC123|some text|some more text|00001 00002 0003 0004 000019|000003|Item I have searched and found an example to remove the extra new line characters using grep and sed, but it (I think) assumes the lines start with a number and the... (5 Replies)
Discussion started by: c56444
5 Replies

7. Shell Programming and Scripting

sed replace characters in next line with input from a file

Hi, I have a set of strings in filea. I want to search string xyz in fileb and replace next line in file b with the content from filea. #cat filea abc def ghi #cat fileb asdkjdslka sajljskdjoi xyzjjjjkko aaaaaaaa bbbbbbbb cccccccc xyzsdsajd dddddddd eeeeeeee (2 Replies)
Discussion started by: anilvk
2 Replies

8. Shell Programming and Scripting

to replace unwanted new line characters

Hi how to replace un wanted new line characters. my file contains data like. ramu,sony,"raju \n ravi \n ramya" \n ravi,sarah,"sowmya \n sorry s\ sangam" \n i want replace new line characters in between double coats with single space. for example $ cat input_file ramu,sony,"raju... (3 Replies)
Discussion started by: Raghava
3 Replies

9. Shell Programming and Scripting

How to replace characters 7 through 14 of every line in a file

Hi all, I have a file with multiple lines. I want to replace characters 7 through 14 of every line with 0000000 Input: 12345678901234567890 23456789012345678901 Output 12345600000004567890 23456700000005678901 Please help. JaK (9 Replies)
Discussion started by: jakSun8
9 Replies

10. Shell Programming and Scripting

Replace string and delete extra characters

Hopefully someone can help out here. This is probably fairly basic, but I've searched and tried several variations of the solutions presented in these forums, so I'll go ahead and ask. How can I locate a string in a file, delete the characters after the string and then replace the string with a... (2 Replies)
Discussion started by: slaubhan
2 Replies
Login or Register to Ask a Question