sed would never choke on this task, no matter how many lines. Even billions of lines. sed just reads one line at a time, so the number of lines is totally not an issue. If I'm wrong about this, I'd like to be educated.
I don't have time at this very moment to consult an implementation's source or run some tests (I might in a few hours), but I would bet that you are wrong about this. The integral type with which line numbers (current input line number and command address line numbers) are implemented will eventually overflow.
Regards,
Alister
---------- Post updated at 10:57 AM ---------- Previous update was at 09:43 AM ----------
Current GNU sed source uses a function named compile_address() to parse command addresses. For numeric addresses (as opposed to regular expression addresses), this function then calls in_integer() to construct the corresponding integer. [1]
countT is an unsigned long integral type [2]. On 32-bit platforms where long is 32-bit, overflow is not implausible, but on a 64-bit UNIX platform, where the LP64 data model specifies a 64-bit long, even extremely large files shouldn't be an issue. That's not to say that there is no limit. There is. It's just much higher, on the order of billions of billions, 2^64 (1.8446744 x 10^19).
Since GNU tools are ported to Microsoft Windows, it's noteworthy that unsigned long remains only 32 bits even on 64 bit Windows (which uses the LLP64 data model, instead of the LP64 adopted by UNIX systems [3], [4]).
A demonstration of overflow on a 32-bit Debian Linux machine with GNU sed 4.1.5 (yes, this is an old version, but that code above, which matches the following behavior, is from the current repository):
A simple overflow check in in_integer() could detect all of these problems, generate a useful error message, abort compilation of the sed script before a single line of data has been read, and return a meaningful exit status.
There's a similar overflow issue with the current line number. It is also a countT integer and it is also not checked for overflow when incremented while reading in the next line of text into the pattern space [5].
This means that that the 4294967297th line in a file is the second instance of a first line. This will cause commands which were only intended for the first line of the file to match a later line. For example, the simple command 1d will delete multiple lines. Specifically, every line for which the following expression is true: (real line number) % 4294967296 == 1
To summarize, in general, the number of lines in a file and the magnitude of the addresses used in the sed script are both restricted by the underlying data type's range. In particular, GNU sed does a terrible job of handling out of range values. Other implementations may not be much better; I did not check.
Hello everybody,
My question is: how to add /tmp/work at the end of line in vi editor.
my file looks like:
cp file1
cp file2
cp file3
****
I need to add " /tmp/work" at the end of each line.
I tried this
:%s/$/" /tmp/work"
and this
:%s/$/\ /tmp/work\/
but it does not work. (2 Replies)
Hi,
how can I add at the begining and at the end of all of the lines of my text file in VI editor ? Many thanks before.
for exemple if in my file i have
line 1
line 2
I want to have :
start line 1 end
start line 2 end (3 Replies)
I am new in hp ux and I want work with vi editor, but in hp ux vi editor the backspaes and del keys doesn't work.
how can I enable them.
thanks (3 Replies)
Hi,
I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question.
How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'?
As i see, p & P options does work only within 'vi'. (10 Replies)
Hi All,
I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by
set EDITOR=vi it does not open a vi editor , rather it do as below.....
/////////////////////////////////////////////////////
$ set... (6 Replies)
Hello All,
Need one Help for one issue.
I am using a French Keyboard, so @ sign is on key 0 and i have to use right Alt + 0 to print it.
It is working everywhere but not inside Vi editor. I can type @ in shell, in notepad. But inside Vi editor it is not working, another problem is that if... (2 Replies)
I was looking through the topics and I wasn't sure if this was the best place to post this question:
I was wondering, out of curiosity, which software everyone was using to code their scripts in. I do mostly sh/ksh and my favorite has always been EditPlus because it is small, fast, yet powerful.... (409 Replies)