The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare columns from seven files and print the output smriti_shridhar Shell Programming and Scripting 7 06-10-2008 09:22 PM
AWK script to print all the columns excpet the one specified kn.naresh Shell Programming and Scripting 3 05-22-2008 04:34 AM
read input from 2 files and print them in alternate columns sriram.s Shell Programming and Scripting 1 02-27-2008 10:12 AM
Print lines with search string at specific position HealthyGuy Shell Programming and Scripting 4 12-04-2006 05:47 AM
Print last 4 columns (variable column #) Da_Duck UNIX for Dummies Questions & Answers 19 02-27-2004 06:33 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-26-2007
Registered User
 

Join Date: Apr 2007
Posts: 9
Stumble this Post!
Can I search columns and print lines?

Hi. First post here.

I'm relatively new to UNIX (Solaris8) and writing my first real script, but I seem to have hit a brick wall. The odd thing is that it seems like it should be a simple task....but not with UNIX apparently.

I've got a large text file: 14000 lines with 10 columns.

I want to search the file purely on column 8 for a particular word, but if that word occurs I want to print the whole line.

If I 'grep' for the word it will show up in the other columns too, but I'm only interested in occurances in column 8.

What I need is something like grep $8 <word> <filename> but of course that command doesn't exist. nawk only deals with columns and won't give me the whole line.

Is there any way I can do this?

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-26-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Code:
nawk -F"<field_separator>" ' $8 == "word" ' filename
Reply With Quote
  #3 (permalink)  
Old 04-26-2007
Registered User
 

Join Date: Apr 2007
Posts: 9
Stumble this Post!
That worked great.

Thanks for your help.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0