我想从管道分隔文件中删除除|,_,-和.s以外的所有特殊字符。
例如,我的数据文件看起来像..
ABCD|123|Name
EFGH|456|New-Name
IJKL|789|New_Name
MNOP|123|New*name
QRST|124|New/name
UVWX|353|Name_*%NAME
EFGH|456|New=Name
Eaba|456|New****Name
fdsf|456|New-----Name
iouk|456|New(#$%^)_Name
我已经尝试了以下方法,但无法达到目标,或者只是一半。
tr -cd '[:print:]' < temp.txt > newfile -- I still get all the special chars.
tr -cd '[:alnum:]' <temp.txt -- I get only aphanum chars but I want to have a few special chars.
cat temp.txt | sed 's/[a-zA-Z0-9|_-.]//g' | sed '/^$/d' -- I get all the special chars but repetition is there
下面给出的输出为
$ cat temp.txt | sed 's/[a-zA-Z0-9|_-.]//g' | sed '/^$/d' | tr -cd '[:print:]' | sort -u
""""){***+#=**~>>\+*****<(")
如果我至少获得了所有唯一的特殊字符,则可以将所有内容放入sed并替换为null。
我的预期输出是:
ABCD|123|Name
EFGH|456|New-Name
IJKL|789|New_Name
MNOP|123|New_name
QRST|124|New_name
UVWX|353|Name_NAME
EFGH|456|New_Name
Eaba|456|New_Name
fdsf|456|New_Name
iouk|456|New_Name
如果需要帮助减少代码,则需要查看特定的列。如前所述,代码必须包含|,_,-字符并删除其他所有内容。 让我知道你们是否正在寻找更多信息。