remove lines between two pattern (inclusive of the pattern) using awk or sed -
my output file below
judi#cat file ---abc--- word1 word2 word3 word4 word5 word6 ---end_abc--- ---def--- line1 line2 line3 line4 ---end_def--- judi#
i need remove lines in between pattern abc , end_abc (inclusive pattern, replace new content , new content in file content of file varies, need use pattern
judi#file1 ---abc--- worda1 worda2 worda3 ---end_abc--- judi#
desired result has
judi# ---abc--- worda1 worda2 worda3 ---end_abc--- ---def--- line1 line2 line3 line4 ---end_def--- judi#
i tried below command
sed '/abc/,/end_abc/{/abc/!{/end_abc/!d}}' file > file 2
but getting below mentioned error
sed: command garbled: /abc/,/end_abc/{/abc/!{/end_abc/!d}}
sed '/end_abc/a ##here' file | sed '/abc/,/end_abc/d' | sed '/##here/r file1' | sed '/##here/d' >file2
output
judi#cat file judi#file1 ---abc--- worda1 worda2 worda3 ---end_abc--- judi# ---def--- line1 line2 line3 line4 ---end_def--- judi#
a ##here appending '##here' after matching /end_abc/
r file1 inserting text file1 after finding pattern '##here'.
Comments
Post a Comment