LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 10:37 AM   #1
Poki
LQ Newbie
 
Registered: Apr 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, 10:57 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 09:27 AM   #3
Poki
LQ Newbie
 
Registered: Apr 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, 09:52 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 09:25 AM   #5
Poki
LQ Newbie
 
Registered: Apr 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



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 12:16 PM
Variables within single quotes are not evaluated? Akhran Linux - Newbie 1 03-10-2006 08:32 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
replacing single quotes in file names adenardo Linux - General 2 05-27-2005 11:29 AM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 10:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:31 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
Open Source Consulting | Domain Registration