[ale] Riddle me this awk man
Greg Freemyer
greg.freemyer at gmail.com
Thu Feb 17 20:21:05 EST 2011
On Thu, Feb 17, 2011 at 8:11 PM, Geoffrey Myers
<lists at serioustechnology.com> wrote:
> Greg Freemyer wrote:
>> All,
>>
>> I'm trying to re-format the first field of a CSV file using AWK.
>>
>> This is what I'm trying which is very close to working:
>>
>> cat supertimeline.csv | awk -F" " '(NR == 1) {print};(NR > 1) { printf
>> "%s-%s-%s %s", $3,$2,$4,$5; $1=""; $2="";$3="";$4=""; $5=""; print
>> substr($0, 5) }' > mysupertimeline.csv
>
>
> To be more specific:
>
> printf "%s-%s-%s %s\n", $3,$2,$4,$5;
Negative.
The first field in the CSV file is space delimited internally and has 5 fields.
So that printf is to print just the first field reformated,
printf "%s-%s-%s %s", $3,$2,$4,$5;
Then I set those 5 fields to null so I don't have to worry with them:
$1=""; $2="";$3="";$4=""; $5="";
Then I print the rest of the original line, but skipping the first 5 delimiters.
print substr($0, 5)
The individual lines seem to be working fine. It's entire missing
lines that are the problem.
Greg
More information about the Ale
mailing list