2010-08-08 24 views

Respuesta

40
sed -n '/matched/,$p' file 
awk '/matched/,0' file 
14

Esta es una versión muy antigua de la sed de GNU en Windows

GNU versión sed 2,05

http://www.gnu.org/software/sed/manual/sed.html

-n only display if Printed 
-e expression to evaluate 
p stands for Print 
$ end of file 
line1,line2 is the range 
! is NOT 

haystack.txt

abc 
def 
ghi 
needle 
want 1 
want 2 

Imprimir línea de juego y las siguientes líneas al final del archivo

>sed.exe -n -e "/needle/,$p" haystack.txt 
needle 
want 1 
want 2 

Imprimir comienzo del archivo hasta, pero no incluyendo la línea coincidente

>sed.exe -n -e "/needle/,$!p" haystack.txt 
abc 
def 
ghi 

Imprimir comienzo del archivo hasta e incluyendo la línea coincidente

>sed.exe -n -e "1,/needle/p" haystack.txt 
abc 
def 
ghi 
needle 

Imprimir todo después de hacer coincidir la línea

>sed.exe -n -e "1,/needle/!p" haystack.txt 
want 1 
want 2 
+0

Gracias: mejor explicación que la marcada. FWIW, otro ejemplo (que desafortunadamente no formateará multiline :-( '# show global/atributos de archivo de algunos archivos netCDF comprimidos' ' DIR = '/ asm/ROMO/cdc/2008cdc/smoke_out/2008ab_08c/12US1/cmaq_cb05_soa/'' ' FN =' emis_mole_all_2008 * '' ' para GZ en $ (busque "$ {DIR}" -maxdepth 1 -tipo -f "$ {FN}" | sort); do' 'echo -e "Procesando $ {GZ}, start = $ (date)" ' ' GZ_FN = "$ (nombre base $ {GZ})" ' ' NETCDF_FN = "$ {GZ_FN% .gz}" ' ' cp $ {GZ}./' ' gunzip ./$ {GZ_FN} ' ' ncdump -h ./${NETCDF_FN} | sed -ne '/ atributos globales /, $ p'' 'echo # newline entre archivos' 'done' – TomRoche

+0

@englebart +1 Realmente buena respuesta, gracias! –

Cuestiones relacionadas