The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Splitting av file in 2 at specific place based on textpattern borgeh Shell Programming and Scripting 0 09-24-2007 07:02 PM
How to retrieve a particular line from a file vinayap UNIX for Dummies Questions & Answers 2 07-11-2007 02:16 PM
search and retrieve previous line in file paulsew Shell Programming and Scripting 2 02-23-2007 08:04 AM
how do we retrieve a line from a file in unix lmadhuri Shell Programming and Scripting 2 02-07-2007 08:07 AM
(cont) Retrieve line from a file based on a value in specific column efernandes UNIX for Dummies Questions & Answers 0 01-27-2007 01:00 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-27-2007
efernandes efernandes is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 5
Post Retrieve line from a file based on a value in specific column

Hi,

I have a file that has several values seperated by ":"
Code:
2006:John:Student:Football:Portugal:Cinema
2006:James:Engineer:Basket:Poland:Theatre
2007:Lucy:Diver:Gymnastic:England:Music
2007:Smith:Plumber:Basket:Spain:Poker
I need make a filter based on the 5th field to find countries that start with a pecific character and then retrieve the lines that match this filter.

Exemple: Find countries starting with 'P'

Result:
2006:John:Student:Football:Portugal:Cinema
2006:James:Engineer:Basket:Poland:Theatre

Thanks
Elio

Last edited by reborg; 01-27-2007 at 10:18 AM..
  #2 (permalink)  
Old 01-27-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
One way using awk:
Code:
awk -F":" '$5 ~ /^P/{print    }' file
Using Python as an alternative:
Code:
#!/usr/bin/python
for line in open("file"):
    if line.split(":")[4].startswith("P"):
        print line.strip()
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0