3

I have a file with many numbers, with each number on one line. My goal is to find the numbers that are missing. I'm trying to generate the sequence of all the numbers with seq

start=$(head -1 numbers.txt)
finish=$(tail -1 numbers.txt)
seq $start $finish > all_numbers.txt

I get the following error message

seq: invalid floating point argument: 4106
Try 'seq --help' for more information.

I'm baffled as 4106 is clearly not a floating point number.

After this I plan to use diff to find the missing numbers. Can someone tell me why seq is behaving this way?

nikhil
  • 992
  • 2
  • 10
  • 16

1 Answers1

6

Probably there's a hidden character after 4106, most probably a carriage return if the file comes from the Microsoft world which you'd need to strip first (or do the whole thing with awk).

$ seq 1 $'2\r'
seq: invalid floating point argument: 2
Try `seq --help' for more information.
$ echo seq 1 $'2\r'
seq 1 2

It's there, but you can't see it. When output to a terminal, it (usually) only moves the cursor to the beginning of the line.

With ksh93, zsh or bash, try:

printf '<%q>\n' "$start"

to see what it contains.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501