简体   繁体   English

sed命令与美元

[英]sed command with dollar

I am trying to understand a shell script which uses the command below: 我正在尝试了解使用以下命令的shell脚本:

sed '$d;1,2 d;s/^ //' $file1 > $file2

I figured s/^ // gets rid of blank lines, but cannot make out what the $d;1,2 d; 我想到s/^ //删除了空行,但是无法确定$d;1,2 d;是什么$d;1,2 d; does. 确实。 Can someone please explain? 有人可以解释一下吗?

This is deleting the last line of the file and the first two lines. 这将删除文件的最后一行和前两行。

The sed 'd'elete command is expecting one or two arguments. sed “D'elete命令期待一个或两个参数。 If one, then the delete will happen for that line; 如果为1,则删除将针对该行;否则为0。 if two, then the delete will happen from the line matching the first argument through the line matching the second. 如果为两个,则删除将从匹配第一个参数的行到匹配第二个参数的行发生。 The arguments can be regular expressions, or line numbers. 参数可以是正则表达式或行号。 sed also recognizes $ for the last line. sed还会在最后一行识别$

So the $d is deleting the last line. 因此, $d将删除最后一行。 and 1,2d is deleting the 1st through 2nd lines. 1,2d删除第一行到第二行。

See man sed for all the gory details. 有关所有血腥细节,请参见man sed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM