Below is my file
$ cat README
login user1
run .profile
cd /u/opt
unzip -l zip file
copy files in zip file to .orig
unzip -o the zip file
cd /u/opt/install
./reqe21.sh
sqlplus admin/<password> @req.sql
logout
I need lines between the matched string last unzip
and logout
i.e desired output is below
cd /u/opt/install
./reqe21.sh
sqlplus admin/<password> @req.sql
I need a couple of answers.
- When I tried
sed -n '/unzip -o /,/logout/p' README
it does not exclude the matching lines.
Thus, I get the below output:
unzip -o the zip file
cd /u/opt/install
./reqe21.sh
sqlplus admin/<password> @req.sql
logout
I tried another solution given here: How can I exclude the lines which matche the range patterns in sed?
But, I do not get the desired output. See below:
$ sed '1,/unzip/d;/logout/,$d' README
copy files in zip file to .orig
unzip -o the zip file
cd /u/opt/install
./reqe21.sh
sqlplus vrcadmin/<password> @req.sql
- How do I use
sed
so that I get the lines between lastunzip
and the lastlogout
i.e the desired output as was shared before.
sed '1,/unzip -o /d;/logout/,$d'
– Quasímodo Jan 08 '21 at 20:18unzip -o
However, how can I get it to consider the last unzip line when I simply giveunzip
and notunzip -o
? – Ashar Jan 08 '21 at 20:21