Last active
February 13, 2023 07:03
-
-
Save rwp0/ba77bafa684e917c957dff4527a00590 to your computer and use it in GitHub Desktop.
Print Specific Line Contents in File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -n -e 'print if $. == 15' file.txt | |
# where $_ is line's content | |
# -n creates: while (<>) { ... } around files, making Perl iterate over lines | |
# -e option's value goes into { ... } | |
# https://perldoc.perl.org/perlvar#$. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -n -e 'print if ARGV -> input_line_number == 15' file.txt | |
# the same as above, but using IO::Handle object method to access the line number | |
# https://perldoc.perl.org/IO::Handle#METHODS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sed -n '15p' file.txt | |
# Or: sh -c "sed -n '15p' `realpath file.txt`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment