Replace newline character between a double quotes to a space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace newline character between a double quotes to a space
# 1  
Old 08-01-2012
Error Replace newline character between a double quotes to a space

Hi Guys,

I have a file with content as below

aj.txt

Code:
"Iam
allfine" abcdef
abcd "all is 
not well"

What I'm trying to say is my data has some new line characters in between quoted text. I must get ride of the newline character that comes in between the quoted text.

output must be:
Code:
"Iamallfine" abcdef
abcd "all is not well"

the machine has SUN OS in it. only korn shell.

please help.

Regards,
Aj

Last edited by Scrutinizer; 08-01-2012 at 03:18 PM.. Reason: code tags
# 2  
Old 08-01-2012
Try:
Code:
/usr/xpg4/bin/awk '(NR-1)%2{$1=$1}1' RS=\" ORS=\" infile

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 08-01-2012
It worked fine. It would be a great help if you can explain it a bit
# 4  
Old 08-01-2012
It worked !!
Attached are the Screenshots!
onlt thing is ther is an extra line in the output with a " in it

please can you explain it. I didn't understand the code. Smilie
Replace newline character between a double quotes to a space-my-tabdelimited-filejpg
Replace newline character between a double quotes to a space-after-commandjpg

Last edited by ajahuja; 08-01-2012 at 05:25 PM..
# 5  
Old 08-01-2012
Yes, I guess it may appear a bit cryptic..

It uses a double quote as input and output record selector (RS=\" ORS=\"). So any record is either inside or outside double quotes. The mod of the line number divided by 2 ( (NR-1)%2 ) determines which is the case. If it is the case then $1=$1 is used to replace any occurrence of the default input field selector (FS), i.e. any combination of consecutive spaces, TABs or newlines to be replaced by the default output field selector (OFS), which is a single space...
The 1 is synonymous for "print the record"..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 08-01-2012
If it is a matter of just joining every two lines, then this might work too:
Code:
paste -d " " - - < infile

# 7  
Old 08-02-2012
Error

oops an issue again !!


Code:
/usr/xpg4/bin/awk '(NR-1)%2{$1=$1}1' RS=\" ORS=\" STD_H.txt > STD_TRUE.txt

/usr/xpg4/bin/awk: line 0 (NR=1561): Record too long (LIMIT: 19999 bytes)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace newline with comma and append quotes

Hi, I have below requirement. Apple Orange Banana Required O/p in bash 'Apple,Orange,Banana' Can you please help. Please wrap your samples, codes in CODE TAGS as per forum rules. (3 Replies)
Discussion started by: Rtk
3 Replies

2. Shell Programming and Scripting

Replace space within quotes

i have an output that i receive and it looks like this: echo '/var/FTPROOT/px/sci/archive/20171102070057904-DY_DC04_Daily Inventory Sync-en-us.csv' '/var/FTPROOT/px/sci/archive/20171102070058291-DY_DC07_Daily Inventory Sync-en-us.csv' what i want to do is replace the spaces in the file names... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Replace space by newline error

Hello I have had a requirement where I need to move data to a new line based on a text .So basically as soon as it encounters :61: it should move to a new line Source Data : :61:D100,74NCH1 :61:D797,50NCH2 :61:D89,38NCHK2 :61:D99,38NCHK12 :61:D79,38NCHK22 :61:D29,38NCHK5 Target Data... (11 Replies)
Discussion started by: kamijia83
11 Replies

4. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

5. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

6. Shell Programming and Scripting

Replace 3rd occurance of SPACE with newline

I have file with SQL output as 0001 firstname1 lastname1 0002 firstname2 lastname2 0003 firstname3 lastname3 0004 firstname4 lastname4 Expected output : 0001 firstname1 lastname1 0002 firstname2 lastname2 0003 firstname3 lastname3 0004 firstname4 lastname4 Let me know if this can... (9 Replies)
Discussion started by: sameermohite
9 Replies

7. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

8. Shell Programming and Scripting

Using sed I want to replace space by newline

Input: -------------------------- 123asd 456sdasda 789a ------------------------- output wanted: --------------------- 123asd 456sdasda 789a ---------------------- I want this by sed in simple way please help (I know by: tr ' ' '\n' < inputfile )I want it by sed only (5 Replies)
Discussion started by: RahulJoshi
5 Replies

9. UNIX for Advanced & Expert Users

newline character, space and tab after a string

no problem (6 Replies)
Discussion started by: angelina
6 Replies

10. UNIX for Dummies Questions & Answers

How can I replace newline character?

Hi, I am trying to write a script to prepare some text for use as web content. What is happening is that all the newlines in the textfile are ignored, so I want to be able to replace/add a few characters so that for a file containg: This is line 1. This is line two. This is line four.... (1 Reply)
Discussion started by: ghoti
1 Replies
Login or Register to Ask a Question