I have a text file which has 10 lines in it . I want to read contents from line 5 and save it in a new file . How can i do this in linux/unix ?
Asked
Active
Viewed 620 times
-2
-
2`head -5 yourfile | tail -1` or `awk 'NR==5' yourfile` – JNevill Nov 13 '18 at 19:24
-
3Possible duplicate of [How to read n-th line from a text file in bash?](https://stackoverflow.com/questions/27056872/how-to-read-n-th-line-from-a-text-file-in-bash) – JNevill Nov 13 '18 at 19:25
-
Missed the "save it in a new file" part. Just stick `> newfile` at the end of any of those commands and you are golden. `>` is "Redirect" where the stdout of the command instead of being sent to the screen for you to see is "redirected" to a file. `>>` is similar but will append to the file instead of overwriting the file. Happy Linuxing! – JNevill Nov 13 '18 at 19:41
-
See [ask] and [mcve] for your next question please. – Nic3500 Nov 13 '18 at 20:35
1 Answers
0
you can use tail
command as
tail -n +5 yourFileName.txt > NewFile.txt
Here you skip first 4 lines of yourFileName.txt
. you get the content from 5th line and save to NewFile.txt

Dileep Jayasundara
- 196
- 1
- 4