awk getline to display first three lines in file

Normand Marion normand.marion at gmail.com
Wed Dec 30 19:03:21 UTC 2015


awk '{ if ( NR <= 3 ) print $0 }' your_file

2015-12-29 10:12 GMT-05:00 asad <a.alii85 at gmail.com>:

> I'm using
>
>     awk 'BEGIN {while((getline gf < "awk.script") > 0) {print gf}}'
>
> to read me first 3 three lines of the pattern. I can do with head -3 . But
> I don't want to since, I have to switch lines between two files.
>
> Suppose awk.script contains
>
>
>     line 1
>     line 2
>     line 3 <------- until here
>     line 4
>
> I have tried updating the original cmd with this
>
>      awk 'BEGIN {while((getline gf < "awk.script") > 0) && f{print
> $gf;f=0};NR<=3{f=1}}'
>
> the code is influenced from the examples give on link:-
>
> http://stackoverflow.com/questions/17908555/printing-with-sed-or-awk-a-line-following-a-matching-pattern
>
> error i'm getting is
>
>     awk: cmd. line:1: BEGIN {while((getline gf < "awk.script") > 0)
> f{print $gf;f=0};NR<=3{f=1}}
>     awk: cmd. line:1:                                                ^
> syntax error
>     awk: cmd. line:1: BEGIN {while((getline gf < "awk.script") > 0)
> f{print $gf;f=0};NR<=3{f=1}}
>     awk: cmd. line:1:
>
> How can it be done? thanks
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>


-- 
*Normand Marion*

normand.marion at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20151230/1847971d/attachment.html>


More information about the ubuntu-users mailing list