Pages

lundi 2 avril 2012

get text of between specific lines using sed

1) sed -n 'linenumber1,linenumber2p'  file
sed -n '10, 20p' file


Similarly, if you want to print from 10 to the end of line you can use: sed -n '10,$p' filename
This is especially useful if you are dealing with a large file. Sometimes you just want to extract a sample without opening the entire file.

If use variables to define the line number, then we need use double quote and {}:
set a = 1
set b = 5
sed -n "$a, ${b}p" stations_igs_final


2) sed -n 5p  file

or use awk:

cat file | awk -v n=5 '{if (NR==n)print $0}'

Aucun commentaire:

Enregistrer un commentaire