LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-06-2014, 03:43 PM   #1
rebelbuttmunch
LQ Newbie
 
Registered: Sep 2011
Posts: 15

Rep: Reputation: Disabled
grep match string between tabs


Hi

I have a file thats tab seperated and I want to match on each line that has a single K entry in a column.

line 1: APPLES ORANGES K BANANS
line 2: SWEETS KIWIS ORANGES

Im using
grep $'\tK' my file but that is matching on both rows. I want to only match on a row that has a tab-K-tab.(line1)

Thanks.
 
Old 06-06-2014, 03:53 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
Its not a tab though,. thats a space.

Code:
grep '\ K\ '
That what you are looking for?
 
Old 06-06-2014, 04:06 PM   #3
rebelbuttmunch
LQ Newbie
 
Registered: Sep 2011
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thanks but it's a tab solution I'm looking for. When I typed the fruity sample the tab took me out of the input box
 
Old 06-06-2014, 04:12 PM   #4
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
This seems to work.
Code:
cat <filename> |grep -P '\t'K'\t'
I created a file like yours (including the misspelling) called "test.txt"
Code:
~$ cat /tmp/test.txt | grep -P '\t'K'\t'
APPLES  ORANGES K       BANANS
jdk
 
1 members found this post helpful.
  


Reply


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
grep question - match exact string Panagiotis_IOA Linux - General 2 01-20-2014 05:34 AM
[SOLVED] Flow control based on grep match pattern or string 123raajesh Linux - Newbie 2 10-30-2013 07:40 AM
How to match with a string containing litteral dot "." with grep command ? coolloo_djack Programming 5 03-17-2010 11:07 PM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 09:55 AM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 10:40 AM


All times are GMT -5. The time now is 10:41 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration