LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 06-24-2009, 11:37 AM   #1
Poki
LQ Newbie
 
Registered: May 2009
Posts: 20

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
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 8,435

Rep: Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154
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: 20

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
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 8,435

Rep: Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154
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: 20

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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 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 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 05:05 AM.

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