Use exit after print. It will not keep looping through the file
cat file | awk '/Linux/{getline; print;exit}'
题
I need to find only next line to the first matched line in multiple log files. I found below helpful awk command on this site. It prints next line of each matched line. But I need only first match. Please help.
awk '/Linux/{getline; print}' file
cat file Unix Linux Solaris AIX SCO Linux Redhat
above command prints: Solaris Redhat
But I need only next line to first matching line: i.e. Solrais
I can use head command but I think for large files its really not recommended
解决方案
Use exit after print. It will not keep looping through the file
cat file | awk '/Linux/{getline; print;exit}'