//View Tip #495
Similar Tips
» Zero files
» Filter stderr for cron jobs
» Hide files in an image
» An interactive perl shell
» Random line


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 »


Add your comment

Comments are currently disabled
sed '/Last line we want/q' file.txt
Posted 2009-01-26 15:06:06
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
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