我有一个包含此行的文件。
输入
sls="N" stnid="armID"
sls="N" stnid="C-ARM #11 w^Aw^Aw^A^Sg^Aw"
sls="N" stnid="virtualID"
对于我想要输出的我
sls="N" stnid="armID"
sls="N" stnid=""
sls="N" stnid="virtualID"
我想上传“C-ARM#11 w ^ Aw ^ Aw ^ A ^ Sg ^ Aw”并将其替换为空白。
问题在于我找不到可以取代它的正则表达式。
我试过sed -e s // ^ // g s / A // g myfile> newfile中。
它不起作用。
还有一个问题是,当我使用CAT myfile时,它并没有显示^ A& ^ S字符。 文件看起来像这样。
sls="N" stnid="armID"
sls="N" stnid="C-ARM #11 wwwgw"
sls="N" stnid="virtualID"
请提前帮助,谢谢。
帕尔
答案 0 :(得分:1)
^ A和^ S是不可打印的ASCII字符的文本表示。字符串实际上不包含子字符串“^ A”和“^ S”。我相信^ A是ascii代码1而^ S是19.要在sed输入中包含原始ASCII字符,请使用$(echo“\ 001”)和$(echo“\ 013”)。
答案 1 :(得分:0)
看起来这些是控制字符(^A
实际上是ASCII码1的非打印字符)。我可以想出两种方法来解决这个问题。首先,尝试匹配
# If you get the pattern of characters right, this will work:
sed -e 's/C-ARM #11 w.w.w..g.w//' myfile > newfile
# This will be less precise, but should still work:
sed -e 's/C-ARM #11 .*"/"/' myfile > newfile
或使用cat
将这些非打印字符转换为打印字符,然后使用sed
:
cat -A myfile > myfile.fixed
sed -e 's/C-ARM #11 w^Aw^Aw^A^Sg^Aw//' myfile.fixed > newfile