On Sat, Oct 07, 2000 at 04:51:05PM -0700, Cory Petkovsek wrote:
>
>Hi everyone,
>
>I'm looking for a console based text utility with a particular function.  
>I don't have one on my system that will do what I am needing.  I'm wondering
>if anyone has or has heard of something that matches.  I've needed this 
>particular function several times, however have had to do the work manually.
>It's worth my time to write it myself, but I'd rather not duplicate work.
>
>I'm looking for a particular utility (call it 'rep' for now) that will 
>repeat a command or output text for every line of a text file, or some 
>program that I can duplicate this function with.
>
>For instance, let's say I wanted to append a '>' to the beginning of every
>line in a file.  This might be done with a command line as:
>    cat file1 | rep -o \> x > file2     
>where x denotes the location of each line (ie \> before the line), and -o 
>means output instead of execute.
>

[snip more details in same vein]

It sounds like what you are looking for is "sed", the Stream EDitor.  It
takes standard input (usually a file, but it could be any sort of text stream)
and applies edits to it that follow the editing syntax found in ed and vi.
Your example above would be:
cat file1 | sed -e "s/^/>/" > file2

For more complex edits, you can compose a sed script with each editing
rule on a different line.  Rules are applied to each line in the input file,
unless explicitly marked otherwise.  Usually they match and replace on 
regular expressions.

Awk and perl, while usually regarded as scripting languages, can also be
applied to this task; it is actually their original mission.

-- 
It's a hard work, being a network pusher. Your customers beep you in
the middle of the night, hungry for another fix. But, what can you do?
Customer satisfaction and all that crap...
Pays good, though.                    --Ingvar the Grey, in the Monastery

Reply via email to