Computing.Net > Forums > Unix > using xargs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

using xargs

Reply to Message Icon

Name: anna
Date: June 25, 2003 at 02:12:47 Pacific
OS: -
CPU/Ram: -
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 25, 2003 at 06:59:22 Pacific
Reply:

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 script

Regards,

Nails


0

Response Number 2
Name: anna
Date: June 25, 2003 at 18:11:51 Pacific
Reply:

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.


0

Response Number 3
Name: nails
Date: June 25, 2003 at 22:37:25 Pacific
Reply:

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 $str

just executing:

$str

won't work. eval forces the variables above to be arguments to the shell.

Regards,

Nails


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Remove blank lines betwee... how to create a beep tone...



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: using xargs

Script to scan files for a string www.computing.net/answers/unix/script-to-scan-files-for-a-string/7532.html

The parameter list is too long (AIX) www.computing.net/answers/unix/the-parameter-list-is-too-long-aix/2584.html

The parameter list is too long www.computing.net/answers/unix/the-parameter-list-is-too-long/3585.html