6

I'm trying to extract an address from a file.

grep keyword /path/to/file

is how I'm finding the line of code I want. The output is something like

var=http://address

Is there a way I can get only the part directly after the = i.e. http://address , considering the keyword I'm greping for is both in the var and http://address parts

0

3 Answers 3

12
grep keyword /path/to/file | cut -d= -f2-
Sign up to request clarification or add additional context in comments.

Comments

8

Just pipe to cut:

grep keyword /path/to/file | cut -d '=' -f 2

1 Comment

I needed a list of theme names from a directory with files like this: theme-xcode.js, where I just needed the "xcode" bit. This answer helped me. I like to understand, so commenting what I learned: -f is the 1-based position of the result of the cut. So, here I get the xcode.js from the first cut, and then just xcode from the second: ls | grep theme | cut -d '-' -f 2 | cut -d '.' -f 1
5

You can avoid the needless pipes:

awk -F= '/keyword/{print $2}' /path/to/file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.