Print all lines in a row except the last one with awk

Hi again,
is it possible to do the following using awk?

input file is

4.465E+17
5.423E+16
1.218E+17
2.600E+16
9.135E+15
1.238E+14
...
6.238E+14

desired output

4.465E+17 &
5.423E+16 &
1.218E+17 &
2.600E+16 &
9.135E+15 &
1.238E+14 &
...       &
6.238E+14

Thanks,
S.

That's easier with sed unless you process the file with awk anyhow beforehand in which case you should include the append there. Try

sed '$!s/$/ \&/' file
4.465E+17 &
5.423E+16 &
1.218E+17 &
2.600E+16 &
9.135E+15 &
1.238E+14 &
... &
6.238E+14
1 Like

Hello f_o_555,

Could you please try following and let me know if this helps you.

awk 'FNR==NR{count++;next} FNR<count{print $0 FS "&";next} 1'  Input_file  Input_file

Thanks,
R. Singh

1 Like
awk '$1=$1' RS= OFS=" &\n" infile
3 Likes