From the GNU sed documentation:
--file options are given on the command-line, then the first non-option argument on the command line is taken to be the script to be executed.
sed commands each has one non-option argument, which gets treated as the script. It would be better practice to always explicitly put a
-e in front of the script. Then you can write the command this way, as just one command instead of a pipeline:
sed -r -e 's/^[[:alnum:]]*.[[:alnum:]]*.?[a-z]*.[[:blank:]]+[0-9]+[[:blank:]]+IN[[:blank:]]+[A-Z]+[[:blank:]]+//g' \
-e 's/\.*.$//' test
It looks like you are attempting to craft the first regex to validate each column, checking that the first column looks like a domain ending with a dot (
[[:alnum:]]*.[[:alnum:]]*.?[a-z]*.), the second column looks like an integer (
[0-9]+), the third column is
IN, and the fourth columns is a record type (
The regex for the first column probably doesn't work the way you expect. Each
. means "match any character"; it does not mean "match a dot character". To match a dot character, you would write
If you just want to extract the last column without validation, and suppressing the trailing dot, you could just write instead:
sed -e 's/.*[ \t]\([^ \t]*\)\.$/\1/' test
[^ \t]*\.$ should match the last column ("all non-space characters followed by a dot at the end of the line"). The parentheses capture everything except the trailing dot.
\1 is a backreference referring to the first and only captured group.
I've opted to use
[ \t] instead of
[[:blank:]] because the latter is an extended regular expression, which is a non-standard GNU extension, and the
-r option makes your command less portable.