@Obsolesce said in Searching for text in file:
@dafyre said in Searching for text in file:
@Pete-S said in Searching for text in file:
If you have a text file that looks like this:
start_folder='/folder1/abc.txt' iterations='123' passphrase='xyz' last_command='invoke' return_value='0'How can you pick out just xyz when looking for "passphrase"?
I know grep will get me the line but what should I use if I want just a part of the line?
Can it be done in one command or do I have to pipe several together?If you the text has a character that would be a good delimiter, you can pipe grep to cut... ie:
cat myfile.txt|grep "iterations"|cut -d '=' -f 2 Output: '123'the -f # is which column you want.
There may be other ways to do it, but that's the first way I can think of.
You can specify a file with grep, no need to pipe in from cat.
This is true! I always seem to get it backwards when I do that, so i just cat $thefile | grep | blah ... Cuts down on frustration, ha ha.