Extract substring before = sign using awk

1

1

Say I have some file with a bunch of lines in the form

someString=someMoreCharacters
anotherString.blah=foo=bar
blah.blah.blah=foo.bar.=foobar

Desired output

someString
anotherString.blah
blah.blah.blah

I want to use awk to extract the substring that starts at the beginning of the line and goes up until, but not including the first equals sign. I want to be able to pipe this output to xargs.

well actually

Posted 2012-03-16T17:58:05.610

Reputation: 483

1sed's greediness makes this a quick fix, sed 's/=.*//', although I've never done anything with awk. – Rob – 2012-03-16T18:06:16.420

Answers

8

In Awk:

awk '{sub(/=.*/, ""); print}' filename

But, I think Rob's solution is easier:

sed 's/=.*//' filename

Hai Vu

Posted 2012-03-16T17:58:05.610

Reputation: 4 824