首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

shell有关问题

2012-02-16 
shell问题源文件为:1,ac1995dsxx, 232,ab1999, 323,ad1971, 234,ae1971xx, 31x表示空格结果1:1,ac1995ds,

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 

热点排行