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.
If file1 looked like this:
Hi everyone,
I'm looking for a console
based text utility.
file2 would look like:
>Hi everyone,
>I'm looking for a console
>based text utility.
Other examples could be:
cat file1 | rep -o \< x \> > file2
<Hi everyone,>
<I'm looking for a console>
And:
find | rep cat x '\| rep -o \\\< x \\\> \> file2'
This would look for all files in the current directory, and all subdirectories.
Notice there are two rep commands. The file listing goes to the first rep
command which would exectute:
cat x | rep \< x \> > file2
for every line (the first x) in the file listing presented by 'find'.
(The repeated \\ tell bash to pass whatever is after the \ to the program.
so \\ is \, \| is |, \> is >. After it's been passed to the first rep by
bash, the first \ is stripped away. So \\\< becomes \<. Bash then passes
this \< to the second rep which becomes <. The '\> file2' at the beginning
becomes > file2 for the 2nd rep command. It then knows to output to this
file. If you ever use the samba client (smbclient), UNC names are a kicker:
smbclient \\\\servername\\share)
Obviously this would keep overwriting file2, however perhaps using x in place
of file2 could denote to overwrite the input file.
What I'm really looking for is something that I can append to the beginning or
end of each file. However something that has much more flexibility, as
as described above, provides much more power.
Thanks,
Cory
By the way, most of you know Microsoft bought 25% (130 million) of Corel.
Be sure to check out mslinux.org (a new level of productivity...) ;)