|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sed or awk deleting text
i have a file where i need to remove text between the delimiters.
say... delimiter1 = start_block delmiter2 = no_block so... start_block <data> no_block i am new to using sed, but i think its something like this, with a variation of gump dumped into the curly brackets at the end of the expression. there are also multiple instances of this in a file, i want this to delete these globally. awk is also a favourable opotion here. sed ':t/start_block/,/no_block/{/no_block/!{$!{N;bt}}/^[0]/d;}' thanks in advance. |
|
#2
|
|||
|
|||
|
Hi
This is how I'd quickly do this in awk: Code:
cat file| awk 'BEGIN {set_delete="N"} {if ($1 == "start_block") set_delete="Y"; if (set_delete == "N") print $0; if ($1 == "end_block") set_delete="N"}'
Basically, the set_delete variable gets set when finding a "start_block" delimiter, skiping the rest of the file until it reaches an "end_block" delimiter. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Sed or awk deleting text |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|