| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
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
On 11/20/2016 1:33 PM, Thierry Blanc [email protected] [sed-users] wrote:
> 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
>
>
> Jim's solution works well:
>
> #!/bin/sed -Ef
> :a
> N
> s/(([^:\n]*)[^\n]*)\n\2(:.*)/\1\3/
> ta
> P
> D
>
> My own, that I found a few minutes after Jim,:
>
> sedscript:
> :eep;
> N;
> s|^([^:]*):([^\n]*)\n\1|\1:\2|;
> teep;
> P;D
>
>
> What I don't understand:
> The 3. line: s|^
> Why is the ^ needed? Without it, the script hangs or loops forever.
>
>
>
>
> On 20/11/16 19:50, Daniel Goldman [email protected] [sed-users] wrote:
>> 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
>
>
>
>>
>> On 11/20/2016 8:05 AM, Thierry Blanc [email protected] [sed-users] wrote:
>>> 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]
>>>
>>>
>>>
>>> ------------------------------------
>>> Posted by: Thierry Blanc <[email protected]>
>>> ------------------------------------
>>>
>>
>> ------------------------------------
>>
>> ------------------------------------
>>
>
>
>
>
> ------------------------------------
>
> ------------------------------------
>
------------------------------------
------------------------------------
--
------------------------------------
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:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/