Reputation: 715
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?
Upvotes: 0
Views: 451
Reputation: 1642
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.
Upvotes: 4