4
Feel free to change the title as it does not match my question 100%
I have something like this in a file:
junk
long_ass_string "/I/want/this/$code/$name" long_ass_string
junk
Clarifying the example:
- The /I/want/this/ part is always the same
- $code and $name are dynamic and different for each string
- Inside long_ass_string there can be more /I/want/this/$code/$name strings and I would like to get all of them.
- The quotation marks (this => ") are present in every /I/want/this/$code/$name string.
So far I've tried...
grep -w "/I/want/this/*" file
# outputs long_ass_string
grep -o "/I/want/this/*" file
# outputs /I/want/this/
Would like to avoid using the solution of getting only x extra characters before and/or after
2Your second command is nearly right, but there are two issues: the quotes are parsed out by
bash
andgrep
doesn't see them; and the wild-card*
is different betweengrep
andbash
: the*
inbash
is equivalent to.*
ingrep
. so what you need isgrep -o '"/I/want/this/.*"'
– AFH – 2017-02-28T14:45:49.647@AFH that's true but executing it returns long_ass_string – sysfiend – 2017-02-28T15:13:03.160
It didn't for me:
echo 'long_ass_string "/I/want/this/$code/$name" long_ass_string'|grep -o '"/I/want/this/.*"'
returns"/I/want/this/$code/$name"
. – AFH – 2017-02-28T16:22:42.690