Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search backwards can't find strings on large files with lots of carriage-returns #40

Closed
DurvalMenezes opened this issue Dec 8, 2019 · 3 comments

Comments

@DurvalMenezes
Copy link

When searching backwards (ie, first going all the way to EOF by typing G and then using ?string), less reports that the string can't be found when it was obviously there (e.g, copy-pasted using the mouse from the initial screenful, before typing G).

I've been using less for over 20 years and have not seen this until now; the only possible causes I can attribute to this issue is that the file is relatively large (~2.3GB) and has a lot (eg, millions) of lines terminating on a single ^M (carriage-return with no line-feed).

in fact, after replacing all carriage-returns with newlines on the file, eg with bbe -e 's/\r/\n/g' <large_file_with_carriage-returns >large_input_file_with_newlines and then running less large_input_file_with_newlines instead, backwards search now works, successfully locating the same strings it failed to find in file_with_carriage-returns.

More details:

$ less --version
    less 530 (PCRE regular expressions)
   [...]
$ sw_vers
   ProductName:    Mac OS X
   ProductVersion: 10.13.6
   BuildVersion:   17G2208
@gwsw
Copy link
Owner

gwsw commented Dec 22, 2019

If the file contains no newline characters, it's seen by less as one gigantic line. So searching won't work because it's viewing everything as being on the same line. When you search for text, it thinks you're already on that line so it doesn't need to move. Less wasn't really intended for viewing non-text files, meaning files which isn't predominantly printable characters in reasonable length lines separated by newlines.

@DurvalMenezes
Copy link
Author

When you search for text, it thinks you're already on that line so it doesn't need to move.

The issue I detected wasn't less "not moving", was it explicitly saying that the search string was not found.

This is a different situation, right?

@gwsw
Copy link
Owner

gwsw commented Mar 13, 2020

If there is one instance of a string in a file and you are positioned on that line, and you then search for the string, less will not move and will display "Pattern not found", meaning there are no more instances of the pattern to be found in that direction. So I believe it is the same situation as I described.

@gwsw gwsw closed this as completed Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants