Extracting n lines from file linux

Posted: August 2, 2013 in Database
Tags: , , , ,

For extracting lines from file use sed commmand in linux

sed -n '10p,20p' input.txt > output.txt

in the above command -n represent lines and 10 and 20 represents the offset , input.txt is the file from which we are extracting the input and storing the output in output.txt

say if i just need the nth line , then use the command as

sed -n '10p' input.txt > output.txt

The above command will extract only the 10th line

if i need selected lines say 10,15,17

sed -n '10p;15p;17p' input.txt > output.txt

Note : Be careful when you are using the > operator . If it is misplaced entire file will get erased.


Comments are closed.