Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 1
    There's no reason why you can't do it with sed. I think you've misinterpeted @Kusalananda's answer (there is no > before the END_SED, it's the end of a heredoc, not a redirection). For simple things like this, awk vs sed is often a matter of personal preference. I like the verbose readability and procedural style of awk. It's easier to read and understand months later. Other times, whether I use sed or awk (or perl) depends on which one i happen to think of first, or which one seems more fitting for the job. Commented Jun 17, 2016 at 14:05
  • 1
    also, it would be trivially easy to modify either of the above scripts to search for any stanza, just add -v search=dvorak-intl to the command line (before any filenames) when running the script, change the /"dvorak"/ {dvorak++}; line to match($0,"\""search"\"") {found++}; and change all other occurences of the dvorak variable to found. Commented Jun 17, 2016 at 14:13
  • 1
    i wouldn't use this script to insert a line. its job is to find a line number. I'd put that line number into a variable (e.g. $l), and do something like printf "%s\n" "${l}i" 'level3(ralt_switch' w | ed filename Commented Jun 17, 2016 at 14:20
  • 1
    One final comment. change both print NR lines to print NR": "$0; to print the matching lines as well as the line numbers. Commented Jun 17, 2016 at 14:33
  • 1
    for info about editing files in-place with printf and ed: unix.stackexchange.com/questions/287593/… or unix.stackexchange.com/questions/281492/… BTW I forgot the . before the w in my comment above. my mistake, it's required to terminate the insert. Commented Jun 17, 2016 at 14:40