copy the last column in the first position awk

awk, bash, preg-replace, sed, text

Solution

What about this? It is pretty similar to yours.

$ awk '{score=$NF; $NF="#"$NF; print score, $0}' file
1233425 word1 word2 #1233425
49586 word1 word2 word3 #49586

Note that in your case you are emptying `$1`, which is not necessary. Just store `score` as you did and then add `#` to the beginning of `$NF`.

Problem

I want to copy the first value of colum in the first position and comment out the old value. For example : ``` word1 word2 1233425 -----> 1233425 word1 word2 #1233425 word1 word2 word3 49586 -----> 49586 word1 word2 word3 #49586 ``` I don't know the number of words preceding the number. I tried with an awk script : ``` awk '{$1="";score=$NF;$NF="";print $score $0 #$score}' file ``` But It does not work.

Original source