I am trying to understand a shell script which uses the command below:
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;
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. If one, then the delete will happen for that line; 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.
So the $d
is deleting the last line. and 1,2d
is deleting the 1st through 2nd lines.
See man sed
for all the gory details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.