Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Grep / Awk

1 view
Skip to first unread message

The Magnet

unread,
Aug 26, 2009, 6:57:14 PM8/26/09
to

Hi,

I have this line of data: Action = ADD

And I am trying to use this command: action=`cat file.dat | grep
'Action' | awk '{print $1}' | cut -d "=" -f 2`

Most of our files do not have spaces around the equal sign, so this
works. But a few files have the spaces around the equal sign, which
is messing everything up.

Any help on how to get around this?

Many Thanks!

Barry Margolin

unread,
Aug 27, 2009, 1:33:07 AM8/27/09
to
In article
<2c65020b-af06-4fb8...@v36g2000yqv.googlegroups.com>,
The Magnet <a...@unsu.com> wrote:

action=`awk -F' *= *' '/Action/ {print $2}'`

As you can see, awk contains the capabilities of both grep and cut.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

The Magnet

unread,
Aug 27, 2009, 9:52:18 AM8/27/09
to
On Aug 27, 12:33 am, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article
> <2c65020b-af06-4fb8-981c-5b05f28a4...@v36g2000yqv.googlegroups.com>,

Thanks!

0 new messages