Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 从列中删除不可打印字符_Shell_Unix_Unicode - Fatal编程技术网

Shell 从列中删除不可打印字符

Shell 从列中删除不可打印字符,shell,unix,unicode,Shell,Unix,Unicode,我的档案如下 [![在此处输入图像描述][1][1] 我想删除行间不可打印的字符。 有人能帮我吗 我使用了下面的命令,但它正在从整个文件中删除不可打印的字符 tr-dc'[:print:][\n\r' 第1栏、第2栏、第3栏、第4栏、第5栏、第6栏、第7栏、第8栏、第9栏、第10栏 1231042324564756,“带逗号的简单字符串”,“带或不带逗号的字符串”,字符串1,美元,12,70%,8/1/2013 2345512312255564,“字符串,带,多个,逗号”,“字符串带或不带逗号”

我的档案如下

[![在此处输入图像描述][1][1]

我想删除行间不可打印的字符。 有人能帮我吗

我使用了下面的命令,但它正在从整个文件中删除不可打印的字符

tr-dc'[:print:][\n\r'

第1栏、第2栏、第3栏、第4栏、第5栏、第6栏、第7栏、第8栏、第9栏、第10栏
1231042324564756,“带逗号的简单字符串”,“带或不带逗号的字符串”,字符串1,美元,12,70%,8/1/2013
2345512312255564,“字符串,带,多个,逗号”,“字符串带或不带逗号”,字符串2,美元,433,70%,2013年7月15日
2352574535243123,“字符串,带逗号

和-hypens和:半圆“,“带或不带逗号的字符串”,字符串1,CAND,744,70%,5/6/2013 4647615467534544,“长字符串,带逗号

,多个:Colan,“带或不带逗号的字符串”,字符串2,CAND,388,70%,9/21/2013 1231042324564756,“带逗号的简单字符串”,“带或不带逗号的字符串”,字符串1,美元,12,70%,8/1/2013
2345512312255564,“字符串,带,多个,逗号”,“字符串带或不带逗号”,字符串2,美元,433,70%,2013年7月15日 2352574535243123,“字符串,带逗号

和-hypens和:半圆“,“带或不带逗号的字符串”,字符串1,CAND,744,70%,5/6/2013 4647615467534544,“长字符串,带逗号”

,多个:Colan,“带或不带逗号的字符串”,字符串2,CAND,388,70%,9/21/2013

输出应如下所示:

第1栏、第2栏、第3栏、第4栏、第5栏、第6栏、第7栏、第8栏、第9栏、第10栏
1231042324564756,“带逗号的简单字符串”,“带或不带逗号的字符串”,字符串1,美元,12,70%,8/1/2013
2345512312255564,“字符串,带,多个,逗号”,“字符串带或不带逗号”,字符串2,美元,433,70%,2013年7月15日
2352574535243123,“字符串,带逗号,和-hypens和:分号”,“字符串,带或不带逗号”,字符串1,CAND,744,70%,5/6/2013
4647615467534544,“长字符串,带逗号,多个:冒号”,“带或不带逗号的字符串”,字符串2,CAND,388,70%,2013年9月21日
1231042324564756,“带逗号的简单字符串”,“带或不带逗号的字符串”,字符串1,美元,12,70%,8/1/2013
2345512312255564,“字符串,带,多个,逗号”,“字符串带或不带逗号”,字符串2,美元,433,70%,2013年7月15日
2352574535243123,“字符串,带逗号和-hypens和:半圆”,“带或不带逗号的字符串”,字符串1,CAND,744,70%,5/6/2013

4647615467534544,“长字符串,带逗号,多个:冒号”,“带或不带逗号的字符串”,字符串2,CAND,388,70%,9/21/2013

制作带有
\r
的测试文件:

$ awk 'BEGIN{OFS=","; print "a","x\ry","c"}' > file
$ hexdump -C file
00000000  61 2c 78 0d 79 2c 63 0a                           |a,x.y,c.|
$2
$3
中删除非打印内容:

$ awk '
BEGIN { FS="," }                 # set comma as separator
{
    for(i=2;i<=3;i++)            # fields 2 and 3
        gsub(/[^[:print:]]/,"")  # replace all non-printables with ""
}1' file                         # print
a,xy,c
$awk'
开始{FS=“,”}#将逗号设置为分隔符
{

对于(i=2;i替换
for(i=2;i@WalterA谢谢,这是一个失误。得到相同的结果:$awk'>BEGIN{FS=“,”}将逗号设置为分隔符>{>(i=2;i gsub(/[:print://),“”)#将所有不可打印的内容替换为“>}1'Sample_file_excel.csv S.No,Name,ComayName,,,1,ABCD¨S,CLH¨,,,2,DEF¨Roy,Exs,,,3,¨Viv Roy,Wo,,,嗯,我想这些字符毕竟是可以打印的。真的不能根据图片来判断。@JamesBrown我添加了实际的文本文件。请帮助。