Question: On some Unix systems, I can type Ctrl-A or Ctrl-E to move to the beginning or end of the line. On some Unix systems I can not and it just prints ^A or ^E, etc. What controls whether this keystoke works as I expect (move around the command line), or prints the ^A, ^E, etc. character?

Answer: 
Using a bash script:

```
#!/bin/bash

tmp_d=$(mktemp -q -d -t 'replace.XXXXX' || mktemp -q -d)

for f in chr*.out; do
    tmp_f="${tmp_d}/$f"
    n="${f#chr}"
    n="${n%.out}"
    awk -v n="$n" '$3 == "NA" { $3=n }1' "$f" > "$tmp_f"
    mv "$tmp_f" "$f"
done

rm -r "$tmp_d"

```

First we make a tmp directory as we will be creating tmp files

Then we loop through each `chr*.out` file.

* Create a variable for this file in the tmp directory
* remove the `chr` prefix
* remove the `.out` suffix
* `awk` will then replace any `NA` in the third column with the number extracted from the filename and save that to the tmp file
* replace the original file with the tmp file

After the loop finishes we remove the tmp directory. 

*all the tmp stuff can be avoided if you have GAWK which can use the `-i` in place option*
I suggest one `sed` script to handle all files.

```
sed -i 's/         NA  /          1  /' chr{1..22}.out 

```