LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   searching pattern in tab delimited file using grep (https://www.linuxquestions.org/questions/programming-9/searching-pattern-in-tab-delimited-file-using-grep-793130/)

vaibhavs17 03-04-2010 06:44 AM

searching pattern in tab delimited file using grep
 
Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep
If i need to perform multiple search like line having "C and AB" or "B and AB"??

simple grep 'B' 1.text gives both record.

Please help
Thanks in advance
Vaibhav

druuna 03-04-2010 06:48 AM

Hi,

Use grep's -w option: grep -w B 1.txt

-w -> Select only those lines containing matches that form whole words.

Hope this helps.

vaibhavs17 03-04-2010 07:18 AM

Hi,

What about 2nd question?

If i need to perform multiple search like line having "C and AB" or "B and AB"??

Thanks,
Vaibhav

pixellany 03-04-2010 07:23 AM

You can use a pipe to connect two grep commands.

druuna 03-04-2010 07:25 AM

Hi,

What do you actually want to search for: C<tab>AB or a C and AB anywhere in a line (AB X Y C would be an example of the second)?

Assuming you want the first:
grep "C<tab>AB" infile, there is one catch: pressing the tab will tell bash to try to complete the C. You can enter a tab in the search string by first pressing <ctrl-v> followed by pressing the <tab>.

vaibhavs17 03-05-2010 01:02 AM

This is absolutely correct
 
Quote:

Originally Posted by druuna (Post 3885364)
Hi,

Use grep's -w option: grep -w B 1.txt

-w -> Select only those lines containing matches that form whole words.

Hope this helps.


Thanks.
It Worked!


All times are GMT -5. The time now is 05:15 AM.