2010-08-08 5 views

risposta

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

Si tratta di una versione molto vecchia di GNU sed su Windows

GNU versione 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 

Stampa linea di corrispondenza e seguendo le linee alla fine del file

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

inizio Stampa di file di fino a, ma non inclusa la linea di corrispondenza

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

inizio Stampa di file di fino al linea di corrispondenza

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

Stampa tutto dopo la linea di corrispondenza

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

Grazie: spiegazione migliore di quella selezionata. FWIW, un altro esempio (che purtroppo non formerà multilinea :-( '# mostra gli attributi globali/file di alcuni file netCDF compressi' ' DIR = '/ asm/ROMO/cdc/2008cdc/smoke_out/2008ab_08c/12US1/cmaq_cb05_soa/'' ' FN =' emis_mole_all_2008 * '' ' per GZ in $ (trova "$ {DIR}" -maxdepth 1 -tipo f -name "$ {FN}" | ordina); do' 'echo -e "Elaborazione $ {} GZ, start = $ (data)" '' GZ_FN = "$ (basename $ {} GZ)" '' NETCDF_FN = "$ {% .gz GZ_FN}" '' cp $ {GZ}./' ' gunzip ./$ {GZ_FN} ' ' ncdump -h ./${NETCDF_FN} | sed -ne '/ attributi globali /, $ p'' 'echo # newline tra i file' 'done' – TomRoche

+0

@englebart +1 Davvero buona risposta, grazie! –