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.

  • 1
    sed's greediness makes this a quick fix, sed 's/=.*//', although I've never done anything with awk. – Rob Mar 16 '12 at 18:06
6

In Awk:

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

But, I think Rob's solution is easier:

sed 's/=.*//' filename

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.