Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a csv that I want to add a preceding column to and a trailing column. The trailing column is a date (manual string right now). Every time I try to get that date, it ends up replacing some text at the front of the read in data (print $0).

How can I add that info?

Sample data from stdin

UNDEFINED,1089,19.3,-0.1

awk

awk -F, '{ printf ", %, %s\n", $0,"12\/15\/2012"}'

results

, 12/15/2012 1089, 19.3, -0.1

desired results

,UNDEFINED,1089,19.3,-0.1,12/15/2012

I've even tried separating the fields into individual columns, same result. Tried triple double-quotes around the date, same results (maybe an error i can't remember). What am I doing wrong with that date?

share|improve this question
    
Works here if you add another %s to the format specification. –  Thor Feb 16 '13 at 21:40
    
Yeah, here with gnu awk 4.0.1 your original awk command with a %s in place of the lone % works.: awk -F, '{printf ",%s, %s \n", $0, "SOME_DATE"}' –  SuperMagic Feb 16 '13 at 21:46
    
I suspect that's what you meant to type. In any event, I also can't reproduce your indicated results even with the presumed typo.... –  SuperMagic Feb 16 '13 at 21:49
    
ok, thanks for the tip! from my examples, I can't get it to fail either. must be something in the stdin. "cat "ls -t | head -1" | tail -n+9 | awk ..." which i can rework now that i started to use awk. –  greenwar Feb 16 '13 at 21:54
    
You do not need to escape the / between double-quotes. –  Johan Apr 15 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.