I have a very long file which I want to print but skipping the first 1e6 lines for example. I look into the cat man page but I did not see any option to do this. I am looking for a command to do this or a simple bash program.
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
this command will delete the first line and print the rest
This shell script works fine for me:
Used with this sample file (file.txt):
The command (it will extract from second to fourth line in the file):
Output of this command:
Of course, you can improve it, for example by testing that all argument values are the expected :-)
if you want to skip first two line
tail -n +3 <filename>
if you want to skip first x line
tail -n +$((x+1)) <filename>
If you want to see first 10 line you can use sed as below:
or if you want to see lines from 20 to 30 you can use:
Use the sed
delete
command with a range address. For example:Alternatively, if you want to only print a known range use the print command with the
-n
flag:This solution should work reliably on all UNIX systems, regardless of the presence of GNU utilities.