cat /etc/squid/squid.conf| sed -e 's/^#.*//g' | sed -e ':r;N;s/\n$//g;br'
First part:
sed -e 's/^#.*//g'
strips any line beginning (^
) with #
and anything that follows after the hash.
Next part:
sed -e ':r;N;s/\n$//g;br'
r
,N
) in register r,\n$
) with nothing /
/
,r
.Using bash:
cat test | sed -s 's/\([a-zA-Z0-9]\)/\1 /g'
Note that sed
needs the grouping operators (
and )
escaped.
Suppose we have a text file containing the following lines:
number 1 number 3
and that we want to insert number 2
as the second line between number 1
and number 3
, we would issue:
sed -i '2inumber 2' file.txt
where the parts of the fragments represent:
2
the line number,i
for the insert command, andnumber 2
the data that has to be inserted.which will modify the file in-place such that the contents of the file after the insertion becomes:
number 1 number 2 number 3
To print out all the lines between 5
and 10
, issue:
sed -n '5,10p' file.txt
One way to normalize filenames is to pass the name through the streamline editor, sed:
echo "/path/to/file.txt" | LANG=C sed "s/[^\x20\x30-\x39\x40-\x5a\x61-\x7a\x2f\x5c\x5b\x5d]//g"
in order to remove unwanted characters.
The hexadecimal set that sed
matches in the example corresponds to all characters 0
to 9
, a
to z
, A
to Z
plus space, the forward- and backward slashes as well as the square brackets that are used typically to store the YouTube ID within the filename.