Re-assign search.ini search engine section numbers automatically w/ sed or awk

If you, like me, have a soft spot for tweaking search.ini using a plain text editor to customize that file to suite your personal needs in terms of searching, then you certainly came across the time consuming and unpleasant necessity to re-assign consecutive numbers to the search engines' .ini sections.

If you have the *nixish stream editor sed at hand (it is also available as pre-compiled windows binaries), then you can use the attached sed-script to automate the process of giving numbers to search engines. …

I'm sure, you already know to invoke sed with the following script in a manner like ”sed -f renumsearch.sed < search.ini > search-new.ini“. ,)

And finally, here it is: renumsearch.sed.


!/bin/sed -f
# renumsearch -- v1.1.201203072020
# Reinstate sequential numbering of Opera's search.ini sections
# Copyright (C) by XAntares, III 2012.
# Licensed under a Creative Commons CC-by-nc-sa 3.0 Unported license.

/\[Search Engine[ ]\+[0-9]\+/ ! b

:g
x
/^$/ s/.*/0/
x
g

:d
s/9\(_*\)$/_\1/
td

s/^\(_*\)$/1\1/; tn
s/8\(_*\)$/9\1/; tn
s/7\(_*\)$/8\1/; tn
s/6\(_*\)$/7\1/; tn
s/5\(_*\)$/6\1/; tn
s/4\(_*\)$/5\1/; tn
s/3\(_*\)$/4\1/; tn
s/2\(_*\)$/3\1/; tn
s/1\(_*\)$/2\1/; tn
s/0\(_*\)$/1\1/; tn

:n
y/_/0/
h

s/^\(.\+\)$/[Search Engine \1]/

:q

If you like it shorter, you can certainly have it the awk way, too:


#!/bin/awk -f
# renumsearch -- v1.0.201203072222
# Reinstate sequential numbering of Opera's search.ini sections
# Copyright (C) by XAntares, III 2012.
# Licensed under a Creative Commons CC-by-nc-sa 3.0 Unported license.

BEGIN { cnt = 1; FS = "" }

tolower($0) ~ /^\[search engine/ {
printf "[Search Engine %i]\n", cnt++; next
}

{ print }

3 Replies to “Re-assign search.ini search engine section numbers automatically w/ sed or awk”

  1. There you go, should work (if [##] and related [##…] sections are in proper order, ie have no section with another number interleaved):
    #!/bin/awk -f
    # renumsession — v1.0.201203121400
    # Reinstate sequential numbering of Opera’s session.ini sections
    # Copyright (C) by XAntares, III 2012.
    # Licensed under a Creative Commons CC-by-nc-sa 3.0 Unported license.

    BEGIN { cnt = 0; FS = “” }

    tolower($0) ~ /^[[0-9]+[ ]*]/ {
    printf “[%i]n”, ++cnt; next
    }

    match($0, /[[0-9]+(.+)]/, res) {

    printf “[%i%s]n”, cnt, res[1]; next
    }

    { print }
    _______(Might be invoked like this ”awk -f renumsession.awk session_new.ini“.)

  2. A Script to renumber entries in a Opera session file would be useful. :-)So when I hand edit out a few pages it doesn’t cause blank windows to appear when I try to open the session file.

Leave a Reply

Your email address will not be published. Required fields are marked *