LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   xargs removes single quotes after awk (https://www.linuxquestions.org/questions/linux-newbie-8/xargs-removes-single-quotes-after-awk-735316/)

Poki 06-24-2009 10:37 AM

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

colucix 06-24-2009 10:57 AM

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

Poki 06-25-2009 09:27 AM

Quote:

Originally Posted by colucix (Post 3584830)
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?

colucix 06-25-2009 09:52 AM

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'


Poki 06-26-2009 09:25 AM

Quote:

Originally Posted by colucix (Post 3586060)
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


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