LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk syntax to print particular record of xyz file? (http://www.linuxquestions.org/questions/linux-newbie-8/awk-syntax-to-print-particular-record-of-xyz-file-561740/)

johnpaulodonnell 06-14-2007 06:14 AM

awk syntax to print particular record of xyz file?
 
Hi.

Can anyone help me with the awk syntax to print a particular record of an xyz file?

Thanks.

acid_kewpie 06-14-2007 06:48 AM

this sounds an awful lot like homework to me, and your question is pretty vague... what defines a "record" to you? how do yo intend to identity said record?

druuna 06-14-2007 06:50 AM

Hi,

awk '{ print $2 }' infile => prints field number 2
if a line looks like this: A B C D, then B will be printed in the previous example.

If separator isn't a space/tab:
awk -F: '{ print $4 }' infile => prints field number 4
if a line looks like this: V:W:X:Y:Z, then Y will be printed in the previous example.

man awk for the details.

Hope this helps.

johnpaulodonnell 06-14-2007 07:37 AM

Thanks druuna.

awk -v FS="\n" was what I needed

jschiwal 06-14-2007 07:47 AM

If you download the gawk package source you can use the "make pdf" target to produce the book: "Gawk: Effective Awk Programming".


All times are GMT -5. The time now is 02:32 AM.