Shell script to change index value
I have a file that reads
96826999, words
96826321, wotds
96826567, d开发者_运维百科sdsa
96826455,dssdsd
I want to change all number in the first column to be sequential starting at 96826700 so the file ends up looking like
96826700, words
96826701, wotds
96826702, dsdsa
96826703, dssdsd
Belowis the shell script I'm trying to use but I'm missing something can you help?
INDEX=96826700
for i in `cat file`
do
sed 's/^968267[0-9]/'${INDEX}'/g'
INDEX=INDEX +1
done
You can use bash shell (or ksh) without external commands
#!/bin/bash
# tested on bash 4.
IFS="," read a b < file
while IFS="," read x b
do
((a++))
echo "$a,$b"
done < file
awk -F"," 'NR==1{count=$1}{count++;print count"," $2}' temp
精彩评论