If I have a file with 100,000 lines, how can I print lines in a specified range, such as lines 15010 to 15020?
Printing given range of lines using sed-n option is to print 'n' number of lines. in above example 'p' is used to Print the current pattern space. Same as above we can also use 'd' Delete pattern space. Start next cycle.
tail [OPTION]... [ Tail is a command which prints the last few number of lines (10 lines by default) of a certain file, then terminates. Example 1: By default “tail” prints the last 10 lines of a file, then exits.
p - Print out the pattern space (to the standard output). This command is usually only used in conjunction with the -n command-line option. n - If auto-print is not disabled, print the pattern space, then, regardless, replace the pattern space with the next line of input.
Printing specific lines from a file is no exception. To display 13th line, you can use a combination of head and tail: Or, you can use sed command: To display line numbers from 20 to 25, you can combine head and tail commands like this: Or, you can use the sed command like this: Detailed explanation of each command follows next.
Use a combination of head and tail command in the following function the line number x: You can replace x with the line number you want to display. So, let's say you want to display the 13th line of the file.
Printing specific lines from a file is no exception. To display 13th line, you can use a combination of head and tail: head -13 file_name | tail +13 Or, you can use sed command:
The following command will print out lines 200 to 220 from a large file called 'bigfile. The head command will print out the first 220 lines from a file, which is then piped into a tail command that prints out only the last 20 lines of the output generated by the previous command.
sed
:$ sed -n '15010,15020p' input.txt
awk
:$ awk '15010<=NR && NR <=15020' input.txt
head/tail
:$ head -n 15020 input.txt | tail -n $((15020-15010+1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With