LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk queries (https://www.linuxquestions.org/questions/linux-newbie-8/awk-queries-4175551858/)

LYC 08-27-2015 02:28 AM

awk queries
 
Hi,

I have a file that consists of a column as follows:

1111
2222
3333
4444

I use the following to convert to row:

awk '{printf("%s,",$0)}' file

but the output contains the command prompt at the end.

ie: 1111,2222,3333,4444,$

How to have the output without the command prompt?

ie: 1111,2222,3333,4444

Thanks in advance.

syg00 08-27-2015 03:09 AM

Think about why you used printf. Because it doesn't insert a newline.
So you have to insert a newline yourself at the end. Easiest done with a null "print" in an END rule. However that will leave you with a trailing comma - you will need to account for that also.

grail 08-27-2015 03:27 AM

You could also have a look at the ORS variable. HINT:-This can be quick and useful but you will need to consider how you know what the last line will be :)


All times are GMT -5. The time now is 02:20 PM.