[ale] Riddle me this awk man

Geoffrey Myers lists at serioustechnology.com
Thu Feb 17 20:41:33 EST 2011


Greg Freemyer wrote:
> 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.

I think I'd do something like:

awk '{print NR}' supertimeline.csv|sort -u

To make sure I have lines that have a single field.

> 
> Greg


-- 
Until later, Geoffrey

"I predict future happiness for America if they can prevent
the government from wasting the labors of the people under
the pretense of taking care of them."
- Thomas Jefferson


More information about the Ale mailing list