shell如何修改某行某列的值
我有一个文件,里面内容如下;00000000000000000500000005000000050000000500000001000000010000000100000...
我有一个文件,里面内容如下;
00 00 00 00 00 00 00 00 05 00 00 00 05 00 00 00
05 00 00 00 05 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 05 00 00 00 05 00 00 00
05 00 00 00 05 00 00 00 05 00 00 00 05 00 00 00
05 00 00 00 05 00 00 00 00 00 00 00 01 02 00 00
01 02 00 00 01 02 00 00 01 02 00 00 00 00 00 00
01 01 1c 05 00 00 00 00 01 00 45 08 01 00 36 04
01 00 32 00 00 00 00 00 01 00 00 b1 01 00 00 60
01 00 01 45 01 00 04 a7 00 00 00 00 01 00 fe 00
00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00
我想对里面第x行,第y列的数据修改。该怎么写? 展开
00 00 00 00 00 00 00 00 05 00 00 00 05 00 00 00
05 00 00 00 05 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00
01 00 00 00 01 00 00 00 05 00 00 00 05 00 00 00
05 00 00 00 05 00 00 00 05 00 00 00 05 00 00 00
05 00 00 00 05 00 00 00 00 00 00 00 01 02 00 00
01 02 00 00 01 02 00 00 01 02 00 00 00 00 00 00
01 01 1c 05 00 00 00 00 01 00 45 08 01 00 36 04
01 00 32 00 00 00 00 00 01 00 00 b1 01 00 00 60
01 00 01 45 01 00 04 a7 00 00 00 00 01 00 fe 00
00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00
我想对里面第x行,第y列的数据修改。该怎么写? 展开
2个回答
展开全部
可以用Vim打开文件, 定位之后编辑
如果不想使用屏幕编辑器,可以考虑行编辑器 sed 或者 awk
比如要改第二行第四列的05为06
用awk的话可以
awk 'NR==2 {$4="06"}' myfile > mynewfile 即可
NR==2 表示如果是第二行, $4表示第四项, $4="06" 就改成06了
如果不想使用屏幕编辑器,可以考虑行编辑器 sed 或者 awk
比如要改第二行第四列的05为06
用awk的话可以
awk 'NR==2 {$4="06"}' myfile > mynewfile 即可
NR==2 表示如果是第二行, $4表示第四项, $4="06" 就改成06了
追问
我试了这样改不了啊
追答
忘了输出了,呵呵
awk 'NR==2 {$4="06"}{print}' myfile > mynewfile
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询