sed help please
Polytropon
freebsd at edvax.de
Fri Mar 4 04:36:07 UTC 2016
On Thu, 3 Mar 2016 23:05:36 -0500, David Banning wrote:
> I am trying to change hundreds of lines of text. Given the following text;
>
> line 1
> line 2 foo take this text
> line 3
> line 4
> line 5 bar leave this text
> line 6
> line 7
>
> I need a sed command that would take everything between foo and bar -
> including foo and bar.
>
> Ideally the output would look like;
>
> line 1
> line 2
> leave this text
> line 6
> line 7
>
> Keep in mind that foo and bar appear in different
> locations - sometimes at the beginning of a line, sometimes at the end,
> and sometimes in the middle.
Does it have to be sed? When I read your requirement, I immediately
thought about the EXAMPLES section in "man awk", where you'll find:
/start/, /stop/
Print all lines between start/stop pairs.
You could try this first:
awk -f '/foo/, /bar/' < input.txt > output.txt
Not verified, though.
> I found someone who posted the following
> solution;
>
> sed '/foo/,/bar/{s/./x/g}' file
>
> but I found that this does not execute under FreeBSD. I have looked
> around for differences between FreeBSD and other unix like SED operations
> but only see the -s "", regarding backup file.
If this works in GNU sed, you can install it (textproc/gsed) and
the use this command.
> Any pointers would be helpful.
void *some, *helpful, *pointers; :-)
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list