-1

I have a one-line file with no newline character at the end of the line. When i run the following:

diff oneline-file.txt any-file.txt | wc -c

I get:

Warning: missing newline character in oneline-file.txt

Why is this an error? How can i fix it? I could do this first:

echo "\n" >> oneline-file.txt

I'd rather do something that does not change the file. Thx.

jww
  • 97,681
  • 90
  • 411
  • 885
JRomeo
  • 543
  • 1
  • 4
  • 20

3 Answers3

0

Thanks to Barmar. This steered me in the right direction. Here's what I used:

diff <(sed 's/$/\n/g' oneline-file.txt) <(cat any-file.txt) | wc -c 
JRomeo
  • 543
  • 1
  • 4
  • 20
-1

You could pipe the result of your echo into diff, replacing the file name as an argument to diff with - (telling it to get that input from stdin).

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
-1

You can use process substitution to echo the newline after the file:

diff <(cat oneline-file.txt; echo "") any-file.txt | wc -c
Barmar
  • 741,623
  • 53
  • 500
  • 612