|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
How to set cursor in editor to pattern given on command line?Hello all,
I have rather general problem than Fedora specific: is there some simple (the simpler the better) console editor, in which is possible to specify string (or, better, pattern) on its command line so that editor after start will locate in edited file this pattern and will set cursor on it? Just something as "+/{pattern}" option in vim editor does. I want offer to (unexperienced) users edit (in shell script) some configuration files, and this should be done with some simple editor (no Emacs or vi). I think e.g. joe or mcedit is simple enough for these users, but joe nor mcedit cann't? probably? solve this demand (joe's command line option for jump to given line number (+nnn) isn't too much useable for this). Thanks in advance, Frantisek Hanzlik -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
|
|
Re: How to set cursor in editor to pattern given on command line?On 11/02/2009 12:58 AM, Frantisek Hanzlik wrote:
> Hello all, > [...snip...] > Just something as "+/{pattern}" option in vim editor does. > > I want offer to (unexperienced) users edit (in shell script) some > configuration files, and this should be done with some simple editor > (no Emacs or vi). I think e.g. joe or mcedit is simple enough for > these users, but joe nor mcedit cann't? probably? solve this demand > (joe's command line option for jump to given line number (+nnn) isn't > too much useable for this). This is a fairly common requirement when distributing applications which may need config file changes, to inexperienced uses. My approach is generally to provide a command rather have the users open an editor, eg: $ sed -i -e "s/foo = LOOK_FOR/foo = REPLACEMENT/" foo.conf of course you could precede that with something like ... """ ...edit the file in the editor of your choice and change foo = ... OR execute the commands below ... """ hth, regards, - steve -- random non tech spiel: http://lonetwin.blogspot.com/ tech randomness: http://lonehacks.blogspot.com/ what i'm stumbling into: http://lonetwin.stumbleupon.com/ -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
|
|
Re: How to set cursor in editor to pattern given on command line?steve wrote:
> On 11/02/2009 12:58 AM, Frantisek Hanzlik wrote: >> Hello all, >> [...snip...] >> Just something as "+/{pattern}" option in vim editor does. >> >> I want offer to (unexperienced) users edit (in shell script) some >> configuration files, and this should be done with some simple editor >> (no Emacs or vi). I think e.g. joe or mcedit is simple enough for >> these users, but joe nor mcedit cann't? probably? solve this demand >> (joe's command line option for jump to given line number (+nnn) isn't >> too much useable for this). > > This is a fairly common requirement when distributing applications which > may need config file changes, to inexperienced uses. My approach is > generally to provide a command rather have the users open an editor, eg: > > $ sed -i -e "s/foo = LOOK_FOR/foo = REPLACEMENT/" foo.conf > > of course you could precede that with something like ... > > """ > ...edit the file in the editor of your choice and change foo = ... > OR > execute the commands below ... > """ > > hth, > regards, > - steve Hi Steve, I agree that variant with sed is in many respects more foolproof than direct editing, but in my case this isn't practical, as users need to see (and occasionally change) surrounding text too. Thus, classical editor is needed... Regards, Franta -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
|
|
Re: How to set cursor in editor to pattern given on command line?On 02Nov2009 11:27, Frantisek Hanzlik <franta@...> wrote:
| steve wrote: | >On 11/02/2009 12:58 AM, Frantisek Hanzlik wrote: | >>Hello all, | >>[...snip...] | >>Just something as "+/{pattern}" option in vim editor does. | >> | >>I want offer to (unexperienced) users edit (in shell script) some | >>configuration files, and this should be done with some simple editor | >>(no Emacs or vi). I think e.g. joe or mcedit is simple enough for | >>these users, but joe nor mcedit cann't? probably? solve this demand | >>(joe's command line option for jump to given line number (+nnn) isn't | >>too much useable for this). | > | >This is a fairly common requirement when distributing applications which | >may need config file changes, to inexperienced uses. My approach is | >generally to provide a command rather have the users open an editor, eg: | > | >$ sed -i -e "s/foo = LOOK_FOR/foo = REPLACEMENT/" foo.conf | > | >of course you could precede that with something like ... | | I agree that variant with sed is in many respects more foolproof than | direct editing, but in my case this isn't practical, as users need to | see (and occasionally change) surrounding text too. Thus, classical | editor is needed... Ok, you'll have to to this on a per-editor basis, alas. If joe has a +nnn option, try: # or egrep, depend what flavour regexp you're offering n=`grep -n "$pattern" <"$file" | sed 's/:.*//'` joe "+$n" "$file" You'll need to work out variations for other editors, alas. -- Cameron Simpson <cs@...> DoD#743 http://www.cskk.ezoshosting.com/cs/ Forty years from now nursing homes will be filled with demented hackers, studying their blank laptop screens nicely placed on knitted quilts to keep their knees warm. - K. Mitchum -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
|
|
Re: How to set cursor in editor to pattern given on command line?Frantisek Hanzlik wrote:
> I have rather general problem than Fedora specific: > is there some simple (the simpler the better) console editor, > in which is possible to specify string (or, better, pattern) on > its command line so that editor after start will locate in edited > file this pattern and will set cursor on it? > > Just something as "+/{pattern}" option in vim editor does. How does nano +100 /etc/services look to you? (^X means ctrl-X) man nano for more details. If you don’t have it installed, it’s in the “nano” package (what a surprise). Hope this helps, James. -- E-mail: james@ | “My aunt’s camel has fallen in the mirage.” aprilcottage.co.uk | -- “Soul Music”, Terry Pratchett. -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
|
|
Re: How to set cursor in editor to pattern given on command line?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...” -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
|
|
Re: How to set cursor in editor to pattern given on command line?Cameron Simpson wrote:
> On 02Nov2009 11:27, Frantisek Hanzlik<franta@...> wrote: > | steve wrote: > |>On 11/02/2009 12:58 AM, Frantisek Hanzlik wrote: > |>>Hello all, > |>>[...snip...] > |>>Just something as "+/{pattern}" option in vim editor does. > |>> > |>>I want offer to (unexperienced) users edit (in shell script) some > |>>configuration files, and this should be done with some simple editor > |>>(no Emacs or vi). I think e.g. joe or mcedit is simple enough for > |>>these users, but joe nor mcedit cann't? probably? solve this demand > |>>(joe's command line option for jump to given line number (+nnn) isn't > |>>too much useable for this). > |> > |>This is a fairly common requirement when distributing applications which > |>may need config file changes, to inexperienced uses. My approach is > |>generally to provide a command rather have the users open an editor, eg: > |> > |>$ sed -i -e "s/foo = LOOK_FOR/foo = REPLACEMENT/" foo.conf > |> > |>of course you could precede that with something like ... > | > | I agree that variant with sed is in many respects more foolproof than > | direct editing, but in my case this isn't practical, as users need to > | see (and occasionally change) surrounding text too. Thus, classical > | editor is needed... > > Ok, you'll have to to this on a per-editor basis, alas. > > If joe has a +nnn option, try: > > # or egrep, depend what flavour regexp you're offering > n=`grep -n "$pattern"<"$file" | sed 's/:.*//'` > joe "+$n" "$file" > > You'll need to work out variations for other editors, alas. Hello Mr. Cameron and James, thank You for these suggestion. I didn't want just jump to line with searched text, because lines in edited files are long - sometimes up to 300-400 chars (sorry, I'm not author of them :). Then, I want jump right on the edited text. At present it appears as simple editors cannot do this. I have working solution in vim: $ vim -i NONE -S <(echo -e "/SrchdPattern...\\zs/\nnormal n") EditedFile ("...\\zs/\nnormal n" construct is there because I want edit text 3 chars after searching pattern). It seems as my users will must know several vim commands. Or they will had lesser comfort with some simpler editor. Regards, Franta Hanzlik -- fedora-list mailing list fedora-list@... To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines |
| Free embeddable forum powered by Nabble | Forum Help |