LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-14-2007, 07:14 AM   #1
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
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.
 
Old 06-14-2007, 07:48 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
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?
 
Old 06-14-2007, 07:50 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
Old 06-14-2007, 08:37 AM   #4
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
Thanks druuna.

awk -v FS="\n" was what I needed
 
Old 06-14-2007, 08:47 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using awk to print CLI-version of kaddressbook ? Yalla-One Programming 6 11-05-2006 03:51 PM
service xyz start instead of /etc/init.d/xyz start stefaandk Fedora 3 08-01-2006 09:00 PM
awk print lines that doesn't have a pattern huynguye Programming 5 05-04-2006 12:08 PM
awk: How can I return a specified record dimsh Linux - Newbie 4 09-24-2005 12:36 PM
AWK: print field to end, and character count? ridertech Linux - Newbie 1 05-07-2004 06:07 PM


All times are GMT -5. The time now is 10:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration