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

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



Miquel van Smoorenburg wrote:

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.

Because:
summer@Dolphin:~$ grep -o wor.* /var/cache/debconf/templates.dat | tr ' ' '\n' |grep wor.* | sort -u | head
"select-default-wordlist".
'select-default-wordlist'
'select-default-wordlist'.
'select-default-worldlist'.
/etc/init.d/network
/etc/init.d/network'ün
/etc/init.d/network,
/etc/init.d/networking
/etc/init.d/network£¬ÄúºÜ¿ÉÄÜÐèÒªÉ3/4³ý
/etc/init.g/network

--

Cheers
John

-- spambait
1aaaaaaa@computerdatasafe.com.au  Z1aaaaaaa@computerdatasafe.com.au
Tourist pics http://portgeographe.environmentaldisasters.cds.merseine.nu/



Reply to: