Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-21-2015, 10:44 PM   #1
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:

123 456
789 ABE

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

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

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
have you read the awk manpage yet?
Old 01-21-2015, 11:31 PM   #3
Registered: Jul 2012
Posts: 97

Rep: Reputation: Disabled
Yes with awk

awk '{ print $2 }' filename

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


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

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration