2

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?

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.

2
  • Yep that was the issue. – nikhil Oct 4 '12 at 17:37
  • This happened in my case when I scped a file which had Windows (dos) line endings. Running dos2unix (and this post) restored the sanity. Thanks! – Kedar Mhaswade Apr 21 '16 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.