I need to find only next line to matched pattern line in multiple log files. I found below awk command on this site

StackOverflow https://stackoverflow.com/questions/23679011

  •  23-07-2023
  •  | 
  •  

Question

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

Était-ce utile?

La solution

Use exit after print. It will not keep looping through the file

cat file | awk '/Linux/{getline; print;exit}'

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top