Question: I need to convert (when the user does something):

```
adcb

```

to (the next letter of every letter):

```
bedc

```

Currently I am just going with [javascript](/questions/tagged/javascript "show questions tagged 'javascript'") and overwrite the character.

Remember the Pkmn Game Corner?

[![enter image description here](https://i.stack.imgur.com/hU1eQb.jpg)](https://i.stack.imgur.com/hU1eQb.jpg)

Wouldn't it be cool if we could simulate that movement of the character (in the pic, change from 7 to Pikachu)?

PS - I have no idea on how to approach this...

Answer: 
Use Process Substitution
------------------------

In [a comment](https://stackoverflow.com/questions/40792565/scope-of-variables-in-bash-and-rules-for-printing-variables-inside-loops#comment68807556_40792565), you say:

> 
> I thtought I was using grep on data.txt *(sic)*
> 
> 
> 

No. Your current pipeline passes the loop's *results* through grep, not the source file. To do that, you need to rewrite your redirection to use [process substitution](http://wiki.bash-hackers.org/syntax/expansion/proc_subst). For example:

```
count=1
while read a; do
    ((count=count+1))
    if [ $count -le 2 ]
    then
        echo $a
        echo kk
        for word in $a; do
            echo $word
        done
    fi
done < <(fgrep Iteration data.txt)

```
@CodeGnome answered your question but there's other problems with your script that will come back to bite you at some point. (see <https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice> for discussions on some of them and also google quoting shell variables). Just don't do it. Shell scripts are just for sequencing calls to tools and the UNIX tool for manipulating text is awk. In this case all you'd need to do the job robustly, portably and efficiently would be:

```
awk '
/Iteration/ {
    if (++count <= 2) {
        print
        print "kk"
        for (i=1; i<=NF; i++) {
            print $i
        }
    }
}' data.txt

```

and of course it'd be more efficient still if you just stop reading the input when count hits 2:

```
awk '
/Iteration/ {
    print
    print "kk"
    for (i=1; i<=NF; i++) {
        print $i
    }
    if (++count == 2) {
        exit
    }
}' data.txt

```