My output has more than 1 line, so I am trying to match the linebreak at the end of the line and then 开发者_开发技巧have only 1 max occurance. I was trying something like this: ^$output*\n$\{,1\}
but that didn't really work out right.
You can grab the first line of output using the Unix utility head
head -1
What language? In sed: sed -e 's/:/!/g' -e '1q' /etc/passwd
The second command means "quit on line 1".
In perl you can use the m
flag to treat one long, multi-line string as multiple lines and then $
will match the first newline.
In awk you could either make the line number part of the condition: awk '/.../ && NR == 1 { print }'
or you could quit after the first line: awk '/.../ { print } { exit }'
With grep you could limit the file with head: head -1 file | grep pattern
or limit to the first matching line with grep -c 1 pattern file...
精彩评论