我想用awk删除一些可以在一行开头的字符。我要删除的字符是@
和/或=
这是一个文件示例:
@word <= Remove @
=word <= Remove =
@=word <= Remove @ AND =
=@word <= Remove = AND @
目前,我使用sub(/^\@/, "", $0)
删除行尾的@
。如何修改此行,以便删除@
,=
以及它们两者是否存在?
答案 0 :(得分:2)
使用awk
:
awk '{sub(/^[@=]+/, "")}1' File
使用sed
:
sed -r 's/^[@=]+//' File
答案 1 :(得分:1)
在awk中:
$ awk 'gsub(/^[=@]+/,"")||1' file
word <= Remove @
word <= Remove =
word <= Remove @ AND =
word <= Remove = AND @
说明:
awk '
gsub(/^[=@]+/,"") || 1 # replace all leading =s and @s with "" and print nevertheless
' file