LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   substring match in specific column (https://www.linuxquestions.org/questions/linux-newbie-8/substring-match-in-specific-column-948594/)

udiubu 06-05-2012 05:15 AM

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

grail 06-05-2012 05:25 AM

Code:

awk '$2 ~ /^pic/' file

udiubu 06-05-2012 05:29 AM

But of course!!!

Thanks grail.

All the best,

Udiubu


All times are GMT -5. The time now is 12:51 AM.