//View Tip #495
Similar Tips
» Filter stderr for cron jobs
» Zero files
» Random line
» Replace expr by other recursively
» View non-printing characters with cat

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Print a file until a regular expression is matched.
cat file.txt | perl -pe "exit if(/Last line we want/)"


View Comments »




Comments 

Add your comment

Comments are currently disabled
Tesserid
sed '/Last line we want/q' file.txt
Posted 2009-01-26 15:06:06
TesserId
Alternatively: sed -n '/First line we don't want/q; p' file.txt

It helps to understand that Perl inherited may features from sed, awk, and sh (ksh, bash, etc.).  Perl is best when you need to combine features from those various languages. But, when you only need one of the features from one of those old languages, then the most succinct solution will come from that old language.
Posted 2009-01-26 15:17:10
sedder
sed '/last line we want/ q' file.txt
Posted 2009-02-04 10:02:55

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit