[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Which tool, and how, to get partial string from file?



In article <[🔎] 41265EB6.2050202@acu.edu>,
Kent West  <westk@acu.edu> wrote:
>A programmer would know this . . , but not me  ;-)
>
>I'm using a script to build a file by concatenating portions of two 
>other files. Then end result needs to be checked to make sure a certain 
>word shows up in a line.
>
>I know that "grep programm <this email message>" would return the line:
>
> A programmer would know this . . , but not me  ;-)
>
>but what I want returned is just the word "programmer".

sed -ne 's/^.*\(word_here\).*$/\1/p' < file

BTW, why not simply

	if grep -q word file
	then
		# word was present in file
		bla
		bla
	fi

Or "if ! grep -q word file" if you want to do something if word
wasn't present in file.

Mike.
-- 
The question is, what is a "manamanap".
The question is, who cares ?



Reply to: