Hi folks

I have tried posting this in the python forum without any luck (http://www.daniweb.com/forums/post1120606.html#post1120606), as well as on the official Intel Fortran forum (because I have also attempted it in Fortran). I am not one inch closer to solving this.

All I want is to be able to overwrite, with the value of a variable I have read in, whatever text in a given text file is on a specific line and specific position on that line.

Text on all other lines, and on the edited line before and after the specified position on that line, MUST remain unchanged (obviously the actual position on the line would be a range for words or non-single-digit numbers).

This is an old-school Fortran input file, presumably based on punch-card style inputs, hence the need to maintain the physical structure of the input file at all costs. I merely want a script or some code that will permit me to change a value within the input file automatically.

This is driving me insane.

file=$1
line=$2
old=$3
new=$4

awk -v line="$line" -v old="$old" -v new="$new" '
 NR == line { sub( old,new ) }
            { print }
' "$file"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.