我有字符串像下面的端部,如果在所述字符串的末尾取出特定模式,在字符串AWK
Abc \ \ <--- This is With space at the end
Abc \ \ <--- This is Without space at the end
Abc\ \
Abc \\
Abc\\
Abc\
Abc \
上述所有串預期結果,
Abc
在短有任何組合模式的空間& \然後我想刪除它。 我想這樣做,用awk ..
請幫助這個...
我有字符串像下面的端部,如果在所述字符串的末尾取出特定模式,在字符串AWK
Abc \ \ <--- This is With space at the end
Abc \ \ <--- This is Without space at the end
Abc\ \
Abc \\
Abc\\
Abc\
Abc \
上述所有串預期結果,
Abc
在短有任何組合模式的空間& \然後我想刪除它。 我想這樣做,用awk ..
請幫助這個...
使用awk,你可以做類似awk '{gsub(/[ \\]+$/,"")}1' file
測試:
$ cat -A file
Abc \ \ $
Abc \ \$
Abc\ \$
Abc \\$
Abc\\$
Abc\ $
Abc \ $
$ awk '{gsub(/[ \\]+$/,"")}1' file
Abc
Abc
Abc
Abc
Abc
Abc
Abc
正則表達式匹配序列在行尾有連續的空格和反斜槓。
謝謝.. 正如我想... 與這個正則表達式M小周... – Punit
要申請一個單獨置換到各行,使用SED:
sed 's/[ \\]*$//g' file
匹配所有的空格和反斜槓組合在每行的末尾,什麼也沒有更換。
那麼,你有沒有嘗試過什麼? –