LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
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

Reply
 
Thread Tools Search this Thread
Old 06-24-2009, 11:37 AM   #1
Poki
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
Poki is offline     Reply With Quote
Old 06-24-2009, 11:57 AM   #2
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,336
Thanked: 496
Use
Code:
xargs -0
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
colucix is offline     Reply With Quote
Old 06-25-2009, 10:27 AM   #3
Poki
LQ Newbie
 
Registered: May 2009
Posts: 13
Thanked: 0

Original Poster
Quote:
Originally Posted by colucix View Post
Use
Code:
xargs -0
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?
Poki is offline     Reply With Quote
Old 06-25-2009, 10:52 AM   #4
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,336
Thanked: 496
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'
colucix is offline     Reply With Quote
Old 06-26-2009, 10:25 AM   #5
Poki
LQ Newbie
 
Registered: May 2009
Posts: 13
Thanked: 0

Original Poster
Quote:
Originally Posted by colucix View Post
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
Poki is offline     Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variables within single quotes are not evaluated? Akhran Linux - Newbie 1 03-10-2006 09:32 PM
Using single quotes vs double quotes in PHP strings hs123 Programming 6 07-11-2005 12:41 PM
replacing single quotes in file names adenardo Linux - General 2 05-27-2005 12:29 PM
xargs: unmatched single quote akudewan Linux - Newbie 4 02-14-2005 06:48 AM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 11:04 PM


All times are GMT -5. The time now is 04:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration