Nice easy sed question
- Reply: Kurt Hackenberg : "Re: Nice easy sed question"
- Reply: Bob Proulx : "Re: Nice easy sed question"
- Reply: Sad Clouds : "Re: Nice easy sed question"
- Reply: ax disroo : "Re: Nice easy sed question"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 11 Sep 2025 22:14:50 UTC
I'm going quietly crazy here. BSD sed is it's own thing, but I can't see what I'm doing wrong... I've got a file called example.txt: Line 1 Line 2 Line 3 I'm trying to add "New Line" after "Line 2" Both of these should work as far as I know: sed -i.bak '/Line 2/a\New Line' example.txt sed -i.bak -e '/Line 2/a\" -e "New Line' example.txt (BSD requires a backup specification for -i IIRC, or '') If I run it with the -i and have a genuine newline after \ it does write the correct stuff to stdout: # sed '/Line 2/a\ > New Line' example.txt Line 1 Line 2 New Line Line 3 With an -i in any variations of the first two (single command or two -e -e) I just get errors like: ": invalid command code e ": extra characters at the end of N command ": extra characters after \ at the end of a command (All starting with " - why?) The only way I can make it work is with -i.bak and on two lines (as above). The Fine Manual says of 'a': [1addr]a\ text Write text to standard output immediately before each attempt to read a line of input, whether by executing the “N” function or by beginning a new cycle. This implies the newline is required but I'm struggling with finding a sane syntax here. A pointer to some better documentation would be welcome! Or is there a better utility for editing (non-system) configuration files by script I just don't know about? Thanks, Frank.