質問

I want to print all header lines of a file:

perl -wnl -e "/^#/ and print" file.vcf

This works- however, I want to quit after I'm done with the header.

What's wrong with

perl -wnl -e "/^#/ and print else exit" file.vcf

?

役に立ちましたか?

解決

else is a keyword that's found as part of if and unless statements.

perl -wnl -e "if (/^#/) { print } else { exit }" file.vcf

perl -wnl -e "/^#/ ? print : exit" file.vcf

perl -wnl -e "/^#/ or exit; print" file.vcf

perl -wpl -e "/^#/ or exit" file.vcf

perl -wpl -e "/^#/ or last" file.vcf

perl -p -e "/^#/ or last" file.vcf

perl -pe"/^#/ or last" file.vcf

他のヒント

Just do:

perl -wnl -e "/^#/ ? print : exit" file.vcf

Alternatively:

perl -wnl -e "/^#/ && print or exit" file.vcf
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top