File manipulation

I am looking for the shortest / easiest solution to use either SED or AWK to swap two lines in a file, always swapping line 40 with line 41 in a given file. I have not tried anything yet, not sure what I would need to do

A simple way (probably a simpler one) to swap two lines in sed would be:

sed "40h;41G;40d" file
awk 'NR==40 {l=$0; next}; 1 ; NR==41 {print l}' infile

Or in line 40, add the following line to the input buffer, and swap the two lines.
With sed:

sed '
  40{
  N
  s/\(.*\)\(\n\)\(.*\)/\3\2\1/
  }
' file

sed -i ... writes back to the file (if your sed supports it).

Probably a barmy way with vi:-

printf ":40\nddp:wq\n" | vi filename

How I used to struggle before discovering sed...... :o

Robin