For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2004 > Awk newbie help request









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Awk newbie help request
Two Rivers

2004-05-12, 7:19 pm


All I need to do is copy a file after ignoring the first three
characters of the first line of the file...


123hello
456goodbye

becomes

hello
456goodbye

Or, if it is easier, scrap the entire first line, but only the first
line, and leave the rest unchanged. Help appreciated!

2R

Charles Demas

2004-05-12, 7:19 pm

In article <6ujp909ptlob7ph88e1o539fi44q6jdudm@news.3rivers.net>,
Two Rivers <no.e-mail@this.time.thank.you> wrote:
>
>All I need to do is copy a file after ignoring the first three
>characters of the first line of the file...
>
>
>123hello
>456goodbye
>
>becomes
>
>hello
>456goodbye


awk 'NR==1 {sub(/^.../,"")}{print}' infile


>Or, if it is easier, scrap the entire first line, but only the first
>line, and leave the rest unchanged. Help appreciated!


awk 'NR!=1' infile

see also tail

man tail


Chuck Demas

--
Eat Healthy | _ _ | Nothing would be done at all,
Stay Fit | @ @ | If a man waited to do it so well,
Die Anyway | v | That no one could find fault with it.
demas@theworld.com | \___/ | http://world.std.com/~cpd
Patrick TJ McPhee

2004-05-12, 7:19 pm

In article <6ujp909ptlob7ph88e1o539fi44q6jdudm@news.3rivers.net>,
Two Rivers <no.e-mail@this.time.thank.you> wrote:

% All I need to do is copy a file after ignoring the first three
% characters of the first line of the file...

BEGIN { getline; print substr($0, 4) }
{ print }

The NR == 1 thing is a common idiom, but I think getting the line
explicitly is clearer and you never know, getting rid of a test on
each input line might be a bit more efficient.
--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com
Hartmut Henkel

2004-05-12, 7:19 pm

Two Rivers <no.e-mail@this.time.thank.you> wrote:
>
>All I need to do is copy a file after ignoring the first three
>characters of the first line of the file...


Ok, not exactly awk, but anyway...

cat myfile | dd bs=1 skip=3

Regards, Hartmut
--
H. Henkel, Oftersheim
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com