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 01-21-2015, 09:44 PM   #1
bison72
LQ Newbie
 
Registered: May 2012
Posts: 8

Rep: Reputation: Disabled
print column with a string using awk or grep


Hi All,

Using grep command with a defined string, you will get the row. Can I get the column instead of row? For example,

the file content is as below:

AA BB
123 456
789 ABE

execute 'grep ABE file' will give you "789 ABE". Is there any way to get the column:
BB
456
ABE
?

Thank you very much.
 
Old 01-21-2015, 10:30 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
have you read the awk manpage yet?

http://www.grymoire.com/Unix/Awk.html
 
Old 01-21-2015, 10:31 PM   #3
Alpha90
Member
 
Registered: Jul 2012
Posts: 94

Rep: Reputation: Disabled
Yes with awk

Code:
awk '{ print $2 }' filename

Last edited by Alpha90; 01-21-2015 at 10:32 PM.
 
  


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
[SOLVED] Column substitution with grep inside awk inconsistent r_hartman Programming 7 01-29-2014 03:00 AM
[SOLVED] AWK: print all fields in one column cristalp Programming 3 03-14-2012 11:43 AM
assigning column name to awk print in a loop bashprog Programming 5 09-29-2010 01:54 AM
how to grep awk or sed the first row and column Bone11409 Linux - Newbie 2 03-21-2010 08:18 PM
[SOLVED] search a string and print column vikas027 Programming 6 03-14-2010 09:20 AM


All times are GMT -5. The time now is 01:20 AM.

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