OK I am somewhat new to UNIX programming please see what you can do to help.
I have a flat file that is a fixed length file containing different records based on the 1st character of each line. The 1st number at the beginning of the line is the record number, in this case it's record #1.
I need a slick way to change what's in columns 375-389 (currently: 200607211838001) with the 8 byte date, followed by the julian date followed by a 4 digit incremented sequence number (date +%Y%m%d%j$$$$) example: 200805201410001
Before:
1............................200607211838001..............................
2..................................................................................
1............................200607211838001..............................
2..................................................................................
1............................200607211838001..............................
2..................................................................................
1............................200607211838001..............................
After:
1............................200805201410001..............................
2..................................................................................
1............................200805201410002..............................
2..................................................................................
1............................200805201410003..............................
2..................................................................................
1............................200805201410004..............................
I tried this and this does not work because it's stomping over itself in the loop and setting everything to the last incremented value:
z=0
cat ${file}|grep ^1|while read n
do
z=$(( ${z} + 1 ))
z=`awk 'BEGIN {printf("%0.4d\n", '${z}' )}'`
trans=`date +%Y%m%d%j${z}`
awk '{x=1;if (substr($0,1,1)==x ) print substr($0,1,374) "'"${trans}"'" substr($0,390)} {if (substr($0,1,1)!=x ) print }' ${1} > ${1}.new;mv ${1}.new ${1}
done
Again any help would be greatly appreciated.