PS.
Correspondence
[...]
Substitute a string with a line number.
Sed "s/^\(..\)//g; s/#####/\1/g"
Ken wrote:
==========
The backreference is not remembered from one subtitute to the next,
so you have to make a single, more complicated, expression:
sed "s/^\(..\)\([^#]*\)#####/\2\1/" q > qq
Benny wrote:
============
Substitute the first occourence of XY
(on each line), with the line number:
rem #1 name of the file. Output file #2, which contents the result:
sed= #1|sed "N;s/\n/ /;s/\([0-9]*\)\([^X]*\)XY/\2\1/;s/[0-9]* //">#2
I must use it in a large Batch program under construction
for update a web page for a "Christian Café" in my city.
BTW:
Not important (it works), but maybe someone is interested:
Capitalize the first 3 words on each line:
s/^/ /;s/$/aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ/;
s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/;
s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/;
s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/;s/.\{52\}$//;s/ //
Someone was (they wrote back to me - not to the users of the mailing list.)
[...]
Then - Tillman wrote:
=====================
It sometimes does more than needed:
$ echo "word1 Word2 word3 word4 word5" | sed -f sedscr
Word1 Word2 Word3 Word4 word5
$ _
So, Benny wrote:
================
Yes. Sometimes it does more than needed...
If some words allready was capitalized before the proces,
it then still capitalize 3 words.
But that's what it was intended to do.
So, there is no problems - The script was intended to capitalize
some few forgotten words.
For example a list of names:
Some Someone
Joe Bill James
and so on... (2 or 3 words on each line).
If the user forgot some of those capitalizing, then
the script does the rest of them. Ending up with done a fine job.
I know that your reply was for excercise but it was helping me a lot.
:-)
So, I also have done some excercises and now I think that
I found the solution:
s/^/ /
s/$/aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ/
:a
s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/
ta
s/.\{52\}$//
s/ //
The 7 lines above, can be put on one line: sed "s/^/ /;s/$/aAb- And so on..
The existing script for doing capitalizing was worse (pretty bad),
but now it seems to work just fine.
In fact I'm still a SED newbee and must learn from you.
K. Regards, b.pedersen
http://users.cybercity.dk/~bse26236/batutil/help/INDEX.HTM#s
PS. (a batch file):
-------------------
@Set ?=
@Echo %?% off
%?% ::
%?% :: Make a file called Cap_ALL.scr (contents 7 lines):
%?% ::
%?% Type %0 | Find /v "?" > Cap_ALL.scr
%?% ::
%?% ::
%?% :: Capitalize all words on each line:
%?% ::
%?% Sed -f Cap_ALL.scr cap___me.txt > Cap_Done.Txt
%?% Del /p Cap_ALL.scr
%?% Goto End
-?------------------------------------------------------------
s/^/ /
s/$/aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ/
:a
s/ \([a-z]\)\(.*\1\)\(.\)/ \3\2\3/
ta
s/.\{52\}$//
s/ //
------?-------------------------------------------------------
:End %?%
Echo.%?%
Echo %?% All words in the file
Echo %?% cap___me.txt is now Capitalized In A New File Called
Echo %?% Cap_Done.Txt
For %%? in (Echo. Pause Cls Exit :-) do %%?
OOPS.
In Denmark an unemployed get a small payment.
I don't know when I got the time for continue this. I received a letter
from the social authority about my 'out of work'.
They want me on the local school for education about how to start
and switch off a computer.
Have a nice day...
|