Search vs. Action and searching for strings : awk
This is a discussion on Search vs. Action and searching for strings within the awk forums in Programming Languages category; I have awk embedded in a shell script and I am trying to search for a string of text after a certain point in the file and I need to return number of lines with that string and number of lines in the input file. I have the following: Code: set -- $(awk -v lines=$lineslastrun -v pattern="$searchpattern" ' BEGIN { count=0 } NR > lines /pattern/ { count++ } END { print NR; print count } ' $logfile) echo $1 echo $2 In the script, those variables are currently set as: $lineslastrun = 8 $searchpattern = "test data" The file ...
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| I have the following: Code: set -- $(awk -v lines=$lineslastrun -v pattern="$searchpattern" '
BEGIN { count=0 }
NR > lines
/pattern/ { count++ }
END { print NR; print count }
' $logfile)
echo $1
echo $2
$lineslastrun = 8 $searchpattern = "test data" The file being searched: Code: [a.mjglenne@plaxafm1001 ~]$ cat testlog one two three test data five six seven eight nine ten eleven twelve thirteen fourteen fifteen test data seventeen eighteen test data testdata If I run the bash script with 'set -x' I see the following output Code: ++ awk -v lines=8 -v 'pattern=test data' '
BEGIN { count=0 }
NR > lines
/pattern/ { count++ }
END { print NR; print count }
' ./testlog
+ set -- nine ten eleven twelve thirteen fourteen fifteen test data seventeen eighteen test data testdata 20 0
+ echo nine
nine
+ echo ten
ten
Appreciate any help. Thanks |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Searching two tables - one blank search field | usenet | Macromedia Dreamweaver | 1 | 10-20-2008 06:41 AM |
| Google search result to be URL-limited when searching site, but notwhen searching Web | usenet | Javascript | 2 | 02-04-2008 04:01 AM |
| Re: perl DB (pgsql)I: problems searching text strings with ' symbol (es d'ambrose) | usenet | Perl | 0 | 04-14-2007 04:03 AM |
| porblems with search action | usenet | Graphics | 0 | 06-25-2003 12:22 PM |
| Search Engine searching in different sites | usenet | Net Objects Fusion | 0 | 09-28-2000 10:22 AM |
All times are GMT -5. The time now is 09:48 AM.




