LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux 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
  Search this Thread
Old 06-24-2009, 11:37 AM   #1
Poki
LQ Newbie
 
Registered: May 2009
Posts: 21

Rep: Reputation: 0
xargs removes single quotes after awk


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
 
Old 06-24-2009, 11:57 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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
 
Old 06-25-2009, 10:27 AM   #3
Poki
LQ Newbie
 
Registered: May 2009
Posts: 21

Original Poster
Rep: Reputation: 0
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?
 
Old 06-25-2009, 10:52 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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'
 
Old 06-26-2009, 10:25 AM   #5
Poki
LQ Newbie
 
Registered: May 2009
Posts: 21

Original Poster
Rep: Reputation: 0
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
 
  


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
xargs: unmatched single quote akudewan Linux - Newbie 5 07-28-2014 01:16 PM
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 vharishankar 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 fillatre Linux - Software 2 06-05-2004 11:04 PM


All times are GMT -5. The time now is 11:12 AM.

Main Menu
Advertisement
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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration