4

I have two scripted files, say file1 and file2. I want to take the content of file1, change character a to A in file1 and append the output to file2 without modifying the content of file1. I'm trying with:

sed -i ‘s/a/A/g’ file1 >> file2

but this just changes the a to A in file1.

1 Answers1

5

Just remove the -i flag:

sed 's/a/A/g' file1 >> file2

The -i flag is used to edit the specified file in place, so it does just that to file1. From man sed:

-i[SUFFIX], --in-place[=SUFFIX]
   edit files in place (makes backup if SUFFIX supplied)

The reason you get nothing appended to file2 when you use -i is that >> is used to append stdout to the specified file. But since file1 is edited in place due to -i, no output is generated, so nothing is appended to file2.