Input file looks like:1 0 0 000 34442 3 3 456 68753 0 0 023 33004 2 2 211 1000first: I want to have 2 copies of each line:1 0 0 000 34441 0 0 000 34442 3 3 456 68752 3 3 456 68753 0 0 023 33003 0 0 023 33004 2 2 211 10004 2 2 211 1000second: in first copy of each line 3 should be replaced by 2 and 4 should be replaced by 1 and in the second copy of each line, 3 should be replaced by 1 and 4 should be replaced by 2 (the first column is row names and row numbers should not change). So, final output becomes:1 0 0 000 21111 0 0 000 12222 2 2 156 68752 1 1 256 68753 0 0 022 22003 0 0 021 11004 2 2 211 10004 2 2 211 1000any suggestion please? I tried this but it does not work:awk '      { tmp = $2; gsub(3, 2, $2); gsub(4, 1, $2); print}      { $2 = tmp; gsub(3, 1, $2); gsub(4, 2, $2); print}    ' < input > output
How to double each line and change digits within each line differently in linux?
text processing;awk
How to double each line: see here...As to your second request, just save 1st field and the entire line into variables then do the first change, set the 1st field to the initial value and print then restore the line content, do the second change, set the 1st field again to the initial value and print:awk '{t=$1;l=$0;gsub(/3/, 2);gsub(/4/, 1);$1=t;print}{$0=l;gsub(/3/, 1);gsub(/4/, 2);$1=t;print}' infile