Regex, how can I grab just the first line of output?

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.

-------------Problems Reply------------

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...

Category:regex Views:0 Time:2010-11-06
Tags: unix regex

Related post

Copyright (C), All Rights Reserved.

processed in 0.086 (s). 11 q(s)