| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
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/