LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-11-2011, 03:47 AM   #1
Fracker
Member
 
Registered: Mar 2009
Posts: 86

Rep: Reputation: 0
Command to grep complete line


cat filename| awk '{print $3}' | cut -c -3 | cut -c 2- | grep 66

this returns the lines containing "66" at 2nd 2 characters of 3rd column of a line, now i need complete lines for this, how can i do it?
 
Old 05-11-2011, 03:53 AM   #2
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
so if i get this right... you search for line with 66 in it (at the 2nd character of the 3rd column), and when you found that, you want to show the entire line of your result?

for example
Code:
abc def g66 blablabla1
abc def g66 blablabla2
abc def g66 blablabla3
abc def g67 blablabla
you need to get as result
Code:
abc def g66 blablabla1
abc def g66 blablabla2
abc def g66 blablabla3
???
 
Old 05-11-2011, 04:00 AM   #3
Fracker
Member
 
Registered: Mar 2009
Posts: 86

Original Poster
Rep: Reputation: 0
yes just with tiny difference

From
Code:
abc def g663123123 blablabla1
abc def g66921321 blablabla2
abc def g6631231 blablabla3
abc def g673123123 blablabla
this
Code:
abc def g663123123 blablabla1
abc def g66921321 blablabla2
abc def g6631231 blablabla3

Last edited by Fracker; 05-11-2011 at 04:06 AM. Reason: Word changed Partial to Tiny
 
Old 05-11-2011, 04:09 AM   #4
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
and if you do

Code:
cat file | grep 66
but is it possible that there are also '66' in the first column or seconde column, or??
 
Old 05-11-2011, 05:29 AM   #5
Fracker
Member
 
Registered: Mar 2009
Posts: 86

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by brownie_cookie View Post
and if you do

Code:
cat file | grep 66
but is it possible that there are also '66' in the first column or seconde column, or??
Yes there is possibility, even it could be more 66 at column 3 which is why i use the above command which initially get 3rd column then get 1st 3 character and then remove 1 character..
 
Old 05-11-2011, 05:48 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
awk does not need the rest of that guff:
Code:
awk '$3 ~ /^.66/' file
This will now work even if you have:
Quote:
abc def g67316623123 blablabla
This will not be displayed, unlike with the grep.
 
1 members found this post helpful.
Old 05-11-2011, 05:52 AM   #7
Fracker
Member
 
Registered: Mar 2009
Posts: 86

Original Poster
Rep: Reputation: 0
Thanks, this works like a charm
 
  


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
Complete Guide to Using Wine from the Command Line (Ubuntu) indubitableness LinuxAnswers Discussion 2 05-07-2011 08:58 PM
Want to print fouth line after resulted line using grep with tail command saurabhmehan Linux - Newbie 10 08-05-2010 12:38 AM
Grep command and adding a line Treikayan Linux - Newbie 4 07-03-2009 10:57 AM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 05:16 AM
Command line tool to find(1) or grep(1) faster? rsheridan6 Linux - Software 2 02-18-2006 04:50 PM


All times are GMT -5. The time now is 10:04 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