$file1
haha
hello i'm lei
i'm abc
you are right
yes it is
I want to get
file2
haha
i'm abc
yes it is
del line before and after the line contains abc I want to know the two steps 1,del the line before line "abc' ,2 del the line after the "abc
question 2
$file3
haha
hello i'm lei
i'm abc
you are right
yes it is
I want to get
$file4
haha
hello i'm lei
<!-- i'm abc -->
you are right
yes it is
then I want to recover it from file4 to file3
$file2
haha
hello i'm lei
i'm abc
you are right
yes it is
joeyg
2
This appears to be structured like a homework problem, and not a real-life issue. Please explain how this is not homework.
Homework problems must appear in the proper forum and with course information provided - as per our forum rules.
This is not homework, i just want to make the problem clear, so I express it like home work
Thanks
---------- Post updated at 08:31 PM ---------- Previous update was at 09:01 AM ----------
any answer experts
Question 1:
n=$(grep -n "i'm abc" file1|cut -d: -f1)
echo $N
awk -v var=$n '!(NR==var-1||NR==var+1)' file1 > file2
Question 2:
sed "s/i'm abc/<-- i'm abc -->/" file3
sed "s/\(i'm abc\)/<-- \1 -->/" file3
awk '/i'"'"'m abc/ {$0="<--" $0 " -->"}1 ' file3
Question 3: (reverse file4 to file3)
Some solutions are ready for you, now it's your turn to answer it.
kurumi
5
qn1
sed -n '/abc/{x;s/\n.[^\n]*\n*$//;x;H;n;s/.*//g;n};/abc/!{H};${x;p}' file