Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Replace newline character between a double quotes to a space

Tags
awk, grep, replace newline, sed, sed awk grep replace newline, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 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 02: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

The Following User Says Thank You to Scrutinizer For This Useful Post:
ajahuja (08-01-2012)
# 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.
Replace newline character between a double quotes to a space-my-tabdelimited-file-jpg  
Replace newline character between a double quotes to a space-after-command-jpg  


Last edited by ajahuja; 08-01-2012 at 04: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"..
The Following User Says Thank You to Scrutinizer For This Useful Post:
ajahuja (08-01-2012)
# 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 to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace space within quotes SkySmart Shell Programming and Scripting 2 11-14-2017 02:12 AM
Replace space by newline error kamijia83 Shell Programming and Scripting 11 09-10-2015 12:54 AM
Replace Double quotes within double quotes in a column with space while loading a CSV file mlavanya Shell Programming and Scripting 6 05-12-2015 12:05 AM
Replace double quotes with a single quote within a double quoted string pchang Shell Programming and Scripting 32 05-08-2014 05:01 PM
Replace 3rd occurance of SPACE with newline sameermohite Shell Programming and Scripting 9 04-17-2014 07:56 AM
Remove two delimiters, space and double quotes SteveDWin UNIX for Dummies Questions & Answers 4 01-11-2012 07:35 PM
Using sed I want to replace space by newline RahulJoshi Shell Programming and Scripting 5 09-21-2010 09:04 AM
newline character, space and tab after a string angelina UNIX for Advanced & Expert Users 6 07-11-2008 11:10 AM
How to remove a character which is enclosed in Double quotes mohan_tuty UNIX for Advanced & Expert Users 3 06-16-2008 11:55 AM
How can I replace newline character? ghoti UNIX for Dummies Questions & Answers 1 08-16-2001 12:49 PM


All times are GMT -4. The time now is 10:50 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password