我想删除模式匹配后的所有行,但不包括模式匹配行。
在以下示例中,删除匹配“1450/pm2-hmc 2”模式后出现的所有行,而不删除模式匹配行ex:
/root/abhishek/HPC/2023-01-03-1440/pm1-hmc1.txt
/root/abhishek/HPC/2023-01-03-1440/pm1-hmc2.txt
/root/abhishek/HPC/2023-01-03-1440/pm2-hmc0.txt
/root/abhishek/HPC/2023-01-03-1440/pm2-hmc1.txt
/root/abhishek/HPC/2023-01-03-1440/pm2-hmc2.txt
/root/abhishek/HPC/2023-01-03-1445/pm0-hmc0.txt
/root/abhishek/HPC/2023-01-03-1445/pm0-hmc1.txt
/root/abhishek/HPC/2023-01-03-1445/pm0-hmc2.txt
/root/abhishek/HPC/2023-01-03-1445/pm1-hmc0.txt
/root/abhishek/HPC/2023-01-03-1445/pm1-hmc1.txt
/root/abhishek/HPC/2023-01-03-1445/pm1-hmc2.txt
/root/abhishek/HPC/2023-01-03-1445/pm2-hmc0.txt
/root/abhishek/HPC/2023-01-03-1445/pm2-hmc1.txt
/root/abhishek/HPC/2023-01-03-1445/pm2-hmc2.txt
/root/abhishek/HPC/2023-01-03-1450/pm0-hmc0.txt
/root/abhishek/HPC/2023-01-03-1450/pm0-hmc1.txt
/root/abhishek/HPC/2023-01-03-1450/pm0-hmc2.txt
/root/abhishek/HPC/2023-01-03-1450/pm1-hmc0.txt
/root/abhishek/HPC/2023-01-03-1450/pm1-hmc1.txt
/root/abhishek/HPC/2023-01-03-1450/pm1-hmc2.txt
/root/abhishek/HPC/2023-01-03-1450/pm2-hmc0.txt
/root/abhishek/HPC/2023-01-03-1450/pm2-hmc1.txt
/root/abhishek/HPC/2023-01-03-1450/pm2-hmc2.txt
/root/abhishek/HPC/2023-01-03-1455/pm0-hmc0.txt
/root/abhishek/HPC/2023-01-03-1455/pm0-hmc1.txt
/root/abhishek/HPC/2023-01-03-1455/pm0-hmc2.txt
/root/abhishek/HPC/2023-01-03-1455/pm1-hmc0.txt
/root/abhishek/HPC/2023-01-03-1455/pm1-hmc1.txt
/root/abhishek/HPC/2023-01-03-1455/pm1-hmc2.txt
/root/abhishek/HPC/2023-01-03-1455/pm2-hmc0.txt
/root/abhishek/HPC/2023-01-03-1455/pm2-hmc1.txt
/root/abhishek/HPC/2023-01-03-1455/pm2-hmc2.txt
/root/abhishek/HPC/2023-01-03-1500/pm0-hmc0.txt
/root/abhishek/HPC/2023-01-03-1500/pm0-hmc1.txt
/root/abhishek/HPC/2023-01-03-1500/pm0-hmc2.txt
/root/abhishek/HPC/2023-01-03-1500/pm1-hmc0.txt
/root/abhishek/HPC/2023-01-03-1500/pm1-hmc1.txt
/root/abhishek/HPC/2023-01-03-1500/pm1-hmc2.txt
/root/abhishek/HPC/2023-01-03-1500/pm2-hmc0.txt
/root/abhishek/HPC/2023-01-03-1500/pm2-hmc1.txt
/root/abhishek/HPC/2023-01-03-1500/pm2-hmc2.txt
我尝试用下面的命令,但它是删除匹配的模式行也.
sed '/1450\/pm2-hmc2/,$d' input.txt
3条答案
按热度按时间mkshixfv1#
您可以反转条件,即打印从开始到匹配行的所有内容:
hgb9j2n62#
lpwwtiir3#
这应该能解决你的问题