× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Arnie,

Am 12.10.2020 um 13:55 schrieb Arnie Flangehead <arnie.flangehead@xxxxxxxxx>:

Yes, that does work brilliantly, thank you. I would never have guessed a gap between the i and the backslash. The manual says: "[1addr]i\ text" - i.e. no gap. Definitely the most useless manual IBM ever put out (grumble, grumble)

Even the GNU Sed manual page is… not very beginner friendly. Don't worry too much. I had by bruises with it, so I can help you a bit. :-)

1. If I prefered to give the pattern inline how would that change the string? How do I deal with a picky newline in that case?

I failed doing this with ancient sed implementations on Linux, 20 years ago and I always resorted to do it with with an external file being referenced. With today's GNU sed on Linux,

sed '/^ONE IS NICE$/i TWO IS NICER'

does the trick. I already deleted the test files. So, please try yourself. I have a strong suspicion that it was my early years dumbness to disregard the backslash escaping the following newline, in effect removing both chars and thus leaving one line with a blank after the i. (Not tested on older sed, yet!)

2. If I want to change the file rather than display it, how do I arrange the from- and to-file in the string.

cat infile.txt |sed … > outfile.txt

sed … < infile.txt > outfile.txt

sed -i … infile.txt

The former two work always, because standard unix-type I/O-redirection. The latter only in recent implementations of GNU sed. Maybe available in recent PASE (call qp2term).

3. If I don't want the pattern to be the whole line can I just take the ^ and $ off?

Yes. Standard regular expression syntax. Nothing IBM i specific here.

Although I'd like to know how to do it without a script file, I probably will use a script file this time since I have several things to insert in one go - i.e. "Something at the top, something before the line that contains such-and-such, something three lines after that ... and so on", so if there are any snags about multiple actions in a script I'd be glad to know them.

That's probably a good idea. I don't remember any snags at the moment besides "commands will be executed in order". So, don't reference something in line 5 you already deleted in line 3. :-)

:wq! PoC (having mass-edited BIND DNS zone files with sed multiple times)

PGP-Key: DDD3 4ABF 6413 38DE - https://www.pocnet.net/poc-key.asc


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.