How do I search a file for a phrase

November 16, 2011 at 15:11:49
Specs: Linux x86_64
I need to search a file for a phrase, then output all the numbers after that phrase (until I hit another phrase) to a different file? I would like to use Perl

E.g.

Temperature Data
20.09
9.09
6.09
5.40
Pressure Data
2134
1234
7899


See More: How do I search a file for a phrase

Report •


#1
November 16, 2011 at 21:10:51
I don't do perl that well. How about an awk script:

awk ' BEGIN { filename="initial.txt" }
{
if($0 ~ /[A-Za-z]+/ )
   {
   gsub(" ", "") # no spaces in the filename
   filename=$0".txt"
   }
else # print the numbers to the filename
   print $0 >> filename

} ' data.txt


Report •
Related Solutions


Ask Question