When I run it without the ^, as follows:
sedscript:
:eep;
N;
s|([^:]*):([^\n]*)\n\1|\1:\2|;
teep;
P;D
it does not hang here, as I see Jim also observed, but produces
incorrect results:
$ sed -r -f sed.txt input.txt
/home/Journal21/guten-tag.html:9:20/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:9
as opposed to correct results with s|^:
$ sed -r -f sed.txt input.txt
/home/Journal21/guten-tag.html:9:20
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0:9
Here is what I think is happening, spelled out. After doing this, I see
Jim had already see the conclusion. I abbreviate directory names.
With s|^( producing correct results:
- N appends line #2 to PatSpace
- PatSpace is guten:0\nguten:20
- s command runs
- PatSpace is guten:0:20
- t branches
- N appends line #3 to PatSpace
- PatSpace is guten:0:20\nwenig:0
- s command does NOT run
- t does NOT branch
- P prints PatSpace line #1
- D deletes PatSpace line #1
- PatSpace is wenig:0
- Next line is NOT read
- N appends line #4 to PatSpace
- PatSpace is wenig:0\nwenig:9
- s command runs
- PatSpace is wenig:0:9
- t branches
- N fails
- PatSpace is printed
- sed exits
With s|( producing correct results:
- N appends line #2 to PatSpace
- PatSpace is guten:0\nguten:20
- s command runs
- PatSpace is guten:0:20
- t branches
- N appends line #3 to PatSpace
- PatSpace is guten:0:20\nwenig:0
- s command runs # OOPS!!!
- PatSpace is guten:0:20wenig:0
- t branches
- N appends line #4 to PatSpace
- PatSpace is guten:0:20wenig:0\nwenig:9
- s command runs # OOPS!!!
- PatSpace is guten:0:20wenig:0wenig:9
- t branches
- N fails
- PatSpace is printed
- sed exits
Daniel
Post by Thierry Blanc ***@gmx.ch [sed-users]Thanks for the answers.
$ cat input.txt
/home/Journal21/guten-tag.html:9
/home/Journal21/guten-tag.html:20
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:9
or
$ cat input.txt
/home/Journal21/guten-tag.html:9
/home/Journal21/guten-tag.html:20
/home/Journal21/guten-tag.html:11
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:2
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:9
There are one to many lines with same file name but always same multiple
of files for all files.
$ cat output.txt
/home/Journal21/guten-tag.html:9:20
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0:9
or
$ cat output.txt
/home/Journal21/guten-tag.html:9:20:11
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0:9:2
#!/bin/sed -Ef
:a
N
s/(([^:\n]*)[^\n]*)\n\2(:.*)/\1\3/
ta
P
D
:eep;
N;
s|^([^:]*):([^\n]*)\n\1|\1:\2|;
teep;
P;D
The 3. line: s|^
Why is the ^ needed? Without it, the script hangs or loops forever.
Post by Daniel Goldman ***@ehdp.com [sed-users]To clarify exactly what is required...
The transformation is like the following?
$ cat input.txt
/home/Journal21/auf-wiedersehen.html:20
/home/Journal21/guten-tag.html:9
/home/Journal21/guten-tag.html:20
/home/Journal21/weltsicherheitsrat-uneins.html:1
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:9
/home/Journal21/wenn-tote-zu-statistiken-werden.html:20
$ cat output.txt
/home/Journal21/auf-wiedersehen.html:20
/home/Journal21/guten-tag.html:9:20
/home/Journal21/weltsicherheitsrat-uneins.html:1
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0:9
/home/Journal21/wenn-tote-zu-statistiken-werden.html:20
Daniel
Post by Thierry Blanc ***@gmx.ch [sed-users]I have the output of a script in the form
file1/full/path:<number>
file1/full/path:<number>
....
file2/full/path:<number>
I want the output
file1/full/path:<number>:<number> ...file2/full/path:<number>:<number> ...
there might be one or many lines with the same file name.
/home/Journal21/weltsicherheitsrat-uneins.html:9
/home/Journal21/wenig-hoffnung-auf-ein-kriegsende.html:0
/home//Journal21/wenig-hoffnung-auf-ein-kriegsende.html:9
/home/Journal21/wenn-tote-zu-statistiken-werden.html:20
[Non-text portions of this message have been removed]
------------------------------------
------------------------------------
------------------------------------
------------------------------------
------------------------------------
------------------------------------
------------------------------------
------------------------------------
--
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/sed-users/join
(Yahoo! ID required)
<*> To change settings via email:
sed-users-***@yahoogroups.com
sed-users-***@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
sed-users-***@yahoogroups.com
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/