shell有关问题

shell问题
源文件为:
1,ac1995dsxx, 23
2,ab1999, 32
3,ad1971, 23
4,ae1971xx, 31

x表示空格

结果1:1,ac1995ds, 23
2,ab1999, 32
3,ad1971, 23
4,ae1971, 31
就是第2列去除空格;


结果2:
1,1995, 23
2,1999, 32
3,1971, 23
4,1971, 31

就是第2列截取字符串;

问题:求实现这2个结果的shell


awk -F, ‘BEGIN{OFS=","} {gsub(" ", "", $2);print}’ yourfile


awk -F, ‘BEGIN{OFS=","} {$2=substr($2,3,4);print}’ yourfile

Assembly code

sed 's/ \+,/,/' urfile

Assembly code

sed 's/\(.*,\)..\(....\).*\(,.*\)/\1\2\3/' urfile

shell有关问题

相关文章:

你感兴趣的文章:

标签云: