How to set cursor in editor to pattern given on command line?

James Wilkinson fedora at aprilcottage.co.uk
Tue Nov 3 23:11:35 UTC 2009


I wrote:
> How does
> nano +100 /etc/services
> look to you? (^X means ctrl-X)
pressed “Send”, and realised you wanted to open at a regexp, not a fixed
line.

That sounds like a job for shell scripting.

If the file isn’t massive, try something like:
nano +$(grep -n "message submission" /etc/services|head -n1| cut -d: -f1) /etc/services 

That’s
grep -n pattern $FILENAME
to find the pattern, prefixed with the line number. Pipe it through
head -n1
to get the first line with it on, and then through
cut -d: -f1
to get everything before the colon (which will be the line number you
want). Put all of that in `` or in $( ) , which will mean the shell will
interpret the contents of `` or $( ) and put the result (in this case
the line number) there instead.

That should work for any editor which understands the +line-no notation,
which I think is most of them.

Hope this helps,

James.

-- 
E-mail:     james@ | “The letters are Elvish, of an ancient mode, but the
aprilcottage.co.uk | language is that of Microsoft, which I will not utter
                   | here. But this in the Common Tongue is what is said: By
                   | this or any other name, You are well and truly...”




More information about the fedora-list mailing list