Skip to content

Instantly share code, notes, and snippets.

@rwp0
Last active February 13, 2023 07:03
Show Gist options
  • Save rwp0/ba77bafa684e917c957dff4527a00590 to your computer and use it in GitHub Desktop.
Save rwp0/ba77bafa684e917c957dff4527a00590 to your computer and use it in GitHub Desktop.
Print Specific Line Contents in File
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#$.
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
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