LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-05-2012, 05:15 AM   #1
udiubu
Member
 
Registered: Oct 2011
Posts: 73

Rep: Reputation: Disabled
substring match in specific column


Dear all,

I have a matrix with several lines and columns. Befeore doing analysis I want to clean it a bit and get just those lines whose column two match some specific substrings requirements. Here is an example:

Picture pic_alpha_A 224 45
Picture alpha 23 49
Picture pic_alpha_CA 234 56
Picture alpha 88 12
Picture pic_beta_CC 999 456

I would like to have just those line containing "pic" in column two:

Picture pic_alpha_A 224 45
Picture pic_alpha_CA 234 56
Picture pic_beta_CC 999 456

I guess I would need a modified version of this awk below:

awk '$2 == "pic"{print $0}' infile.txt >> outfile.txt

Please note that "pic" is separated from the rest with the "_" delimeter.

Any suggestion is higly appreciated.

Sincerely,

Emiliano
 
Old 06-05-2012, 05:25 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,017

Rep: Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196
Code:
awk '$2 ~ /^pic/' file
 
1 members found this post helpful.
Old 06-05-2012, 05:29 AM   #3
udiubu
Member
 
Registered: Oct 2011
Posts: 73

Original Poster
Rep: Reputation: Disabled
But of course!!!

Thanks grail.

All the best,

Udiubu
 
  


Reply

Tags
awk stdin syntax, column, string


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
Deleting files based on Substring match manushi88 Linux - Newbie 8 04-19-2012 01:14 PM
[SOLVED] Substring with specific condition VinRoh Linux - Newbie 5 02-22-2012 09:21 AM
ls -- changing color of a substring for specific file types linav Linux - General 4 06-20-2008 12:16 PM
how to find an exact substring match? ldp Programming 7 02-22-2005 06:28 AM
perl: substring extraction after specific char markus1982 Programming 2 10-06-2002 05:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:44 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration