Linux - Newbie This forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
06-24-2009, 11:37 AM
#1
LQ Newbie
Registered: May 2009
Posts: 13
Thanked: 0
xargs removes single quotes after awk
[
Log in to
get rid of this advertisement]
Hi All,
my input is
111
222
333
i need to get '111','222','333'
this is what i am doing
more 1.out | awk -v q="'" '{ print q $1 q ","}' | xargs
the last pipeline removes the single quotes tha i am adding with awk.
so the result is 111,222,333
and not '111','222','333'
How can this be fixed?
Thank you
06-24-2009, 11:57 AM
#2
Guru
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,124
Thanked: 460
Use
You don't need the command more, since awk accepts a file as argument:
Code:
awk -v q="'" '{ print q $1 q ","}' 1.out | xargs -0
06-25-2009, 10:27 AM
#3
LQ Newbie
Registered: May 2009
Posts: 13
Thanked: 0
Original Poster
Quote:
Originally Posted by
colucix
Use
You don't need the command more, since awk accepts a file as argument:
Code:
awk -v q="'" '{ print q $1 q ","}' 1.out | xargs -0
thank you so much for your reply.
Do you know how can i have all these variables in one line, one after the other separated by comma?
06-25-2009, 10:52 AM
#4
Guru
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,124
Thanked: 460
Do you mean the content of the file entirely on one line as in your previous example? I'd do something like this:
Code:
$ cat testfile
111
222
333
$ echo $(cat testfile) | sed "s/^/'/;s/ /','/g;s/$/'/"
'111','222','333'
06-26-2009, 10:25 AM
#5
LQ Newbie
Registered: May 2009
Posts: 13
Thanked: 0
Original Poster
Quote:
Originally Posted by
colucix
Do you mean the content of the file entirely on one line as in your previous example? I'd do something like this:
Code:
$ cat testfile
111
222
333
$ echo $(cat testfile) | sed "s/^/'/;s/ /','/g;s/$/'/"
'111','222','333'
Thanks, that is excellent
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 05:12 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News
LQ Podcast
LQ Radio