Sar*_*kar 3 command-line text-processing
我正在尝试删除除字母以外的最后一个字符:
support.help1.com,,
support.help1.com.
support.help1.com9
support.help1.com*
support.help1.com@@
support.help1.com##
support.help1.com%%
support.help1.com^
support.help1.com
support.help1.com,
support.help1.com-
Run Code Online (Sandbox Code Playgroud)
我希望我的输出是这样的:
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
Run Code Online (Sandbox Code Playgroud)
sed 也可能有帮助:
command | sed 's/[^a-Z]*$//g'
# create the example output
$ echo "support.help1.com,,
support.help1.com.
support.help1.com9
support.help1.com*
support.help1.com@@
support.help1.com##
support.help1.com%%
support.help1.com^
support.help1.com
support.help1.com,
support.help1.com-" > trailexample.txt
# now edit this stream
# something like $ command_output | sed
$ cat trailexample.txt | sed 's/[^a-Z]*$//g'
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
support.help1.com
# explanation
# sed (replace) 's/this/by-this/g' :: sed 's/[^a-Z]*$//g'
# s : substitution command, we want to substitute strings
# The 'this' [^a-Z]*$ : regexp pattern
# ^ mean not
# a-Z means all aLphBetiCaL chars
# []* any number of what is in brackets
# $ means end of line
# So the 'this' is 'any number of consecutive non-alphabetical chars before end of line'
# And the 'by-this' is empty, nothing, nada, void :: //
# g : global substitution command, means do the replacement for all occurrences
Run Code Online (Sandbox Code Playgroud)