extract string
Ben Scott
dragonhawk at gmail.com
Tue Jan 10 12:54:01 EST 2006
On 1/10/06, Zhao Peng <greenmt at gmail.com> wrote:
> how could I extract the string which
> contains "univ" and create an output file called def.txt, which only has
> 3 following lines:
Here's one way, as a Perl one-liner:
perl -ne 'split ","; $_ = $_[2]; s/(^")|("$)//g; print if m/univ/;' <
abc.txt > def.txt
That trims out the quotes, as it appears you want. The search for
"univ" is case-sensitive.
Broken down into a script with comments:
#!/usr/bin/perl -n
split ","; # split input fields into @_ (split at commas)
$_ = $_[2]; # grab the third field, put into default workspace ($_)
s/(^")|("$)//g; # delete double-quote (") at start and/or end
print if m/univ/; # print if contains "univ"
HTH,
-- Ben
More information about the gnhlug-discuss
mailing list