Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i am using xargs to combine two lines into one. but the lines have double quoted and single quoted strings which i need to retain. how do i go about this?
ex) line1= the "quick" brown
line2= fox doesn't jump.
combined= the "quick" brown fox doesn't jump.i need to use sed s/\"/\'\"\'/g to be able to retain the ".
sed s/\'/\"\'\"/g to retain the '.
but how do i merge both so i can just pipe the output to xargs?thank you for any help.

Hi:
If I'm not misinterpreting what you want, you need to escape the quotes around 'quick'. I don't see where you need sed or xargs as long as you keep quotes around your two variables:
#!/bin/ksh
line1="the \"quick\" brown"
line2="fox doesn't jump"
echo "$line1" "$line2"or
line3=$(echo "$line1" "$line2")
echo $line3
#end scriptRegards,
Nails

i need to use xargs because aside from merging two or more lines (the number of which is unpredictable), xargs also reduces multiple spaces between words to just one space, for uniformity.
if you can suggest any more, it'd be a big help.
thanks.

Hi:
If you want to reduce the multiple spaces, just remove the double quotes around the two variables:
echo $line1 $line2
I still don't think you need xargs for this particular problem; xargs is just echo on steroids -).
OK, there is a trick for gathering the output of two or more commands and placing it on one line with xargs.
separate all the commands by semi-colon, surrounded by parenthesis and pipe it to xargs:
(id; date)|xargs
The output of the id and date commands goes on one line.
You could do the same thing with the echo command above:
(echo "$line1"; echo "$line2")|xargs
multiple variables is still going to be a problem no matter what method you use. You could build a string and then use the eval command to execute the string:
# all on one line
str="(echo \"$line1\"; echo \"$line2\")|xargs"
eval $strjust executing:
$str
won't work. eval forces the variables above to be arguments to the shell.
Regards,
Nails

![]() |
Remove blank lines betwee...
|
how to create a beep tone...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |