Search code examples
unixcutxargs

Customizing print output after getting a column using 'cut' command


I'm trying to print the first column of output in a "customized" way, after executing a program that prints out a table. I know how to get the first column from the output, but I want to print each row between single quotes. So, right now I have the commands that can get me the first column:

./genTable | cut -f2 | xargs -0 

What can I add to this command so that it prints the values between quotes. For example, the output right now looks like

apple
cider
vinegar

I want it to look like

'apple'
'cider'
'vinegar'

Solution

  • I'd use awk ;-) , i.e.

        ./genTable | awk -v singleQ="'" '{print singleQ $1 singleQ}'
    

    And of course you if you want super-minimalist, change all references from singleQ to Q ;-)

    output

    'apple'
    'cider'
    'vinegar'
    

    IHTH