用空格替换字母数字,数值

时间:2015-06-10 09:37:25

标签: linux shell awk

文件如下所示:

1234567890|asdfg|werty|asfgtr21|12345|zxcv=sdf|zsde=1234
2345678901|we1|sd1=12df|werty|dfghj|sdf=fgh|hjkl

所需的输出是:

1234567890|asdfg|werty|||zxcv=sdf|
2345678901|||werty|dfghj|sdf=fgh|hjkl

1 个答案:

答案 0 :(得分:0)

这就是诀窍:

awk -F'|' '{ printf $1"|"; for (i=2; i<=NF; i++) { if ($i !~ /.*[0-9].*/) printf $i;  printf "|"; } printf "\n"}' file

相同的oneliner split&amp;缩进以更好地理解它:

awk -F'|' '{
    printf $1"|";
    for (i=2; i<=NF; i++) {
        if ($i !~ /.*[0-9].*/)
            printf $i;
        printf "|"
    }
    printf "\n"}' file