我有一个读取文件
96826999, words
96826321, wotds
96826567, dsdsa
96826455,dssdsd
我想将第一列中的所有数字更改为从96826700开始的顺序 所以文件最终看起来像
96826700, words
96826701, wotds
96826702, dsdsa
96826703, dssdsd
下面是我试图使用的shell脚本,但我遗漏了一些你可以帮忙吗?
INDEX=96826700
for i in `cat file`
do
sed 's/^968267[0-9]/'${INDEX}'/g'
INDEX=INDEX +1
done
答案 0 :(得分:5)
您可以在没有外部命令的情况下使用bash shell(或ksh)
#!/bin/bash
# tested on bash 4.
IFS="," read a b < file
while IFS="," read x b
do
((a++))
echo "$a,$b"
done < file
答案 1 :(得分:0)
awk -F"," 'NR==1{count=$1}{count++;print count"," $2}' temp