LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 02:47 AM   #1
Fracker
Member
 
Registered: Mar 2009
Posts: 90

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, 02: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, 03:00 AM   #3
Fracker
Member
 
Registered: Mar 2009
Posts: 90

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 03:06 AM. Reason: Word changed Partial to Tiny
 
Old 05-11-2011, 03: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, 04:29 AM   #5
Fracker
Member
 
Registered: Mar 2009
Posts: 90

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, 04:48 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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, 04:52 AM   #7
Fracker
Member
 
Registered: Mar 2009
Posts: 90

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


Reply



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

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

All times are GMT -5. The time now is 12:24 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
Open Source Consulting | Domain Registration