| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
supposed the sampe data is correct, use
sed 's/ */\t/g' firstfile| sort -n -k 5 -t$'\t' |sed -r
's|^|<TR><TD>|;s|\t|</TD><TD>|g;s|$|</TR>|'
explanation:
1. replace two or more spaces (i.e. column separators) with a tab
2. sort the output numerically according to the last column (needs bash)
3. add html markes at beginning of the line, replace the tabs with html
markers, add html makers at end of line
output:
<TR><TD>google.com</TD><TD>FR</TD><TD>OK</TD><TD>2 September
2015</TD><TD>21</TR>
<TR><TD>ibm.com</TD><TD>ES</TD><TD>OK</TD><TD>November 18,
2015</TD><TD>21</TR>
<TR><TD>mysql.com</TD><TD>US</TD><TD>OK</TD><TD>7 Jul 2016</TD><TD>25</TR>
<TR><TD>sap.com</TD><TD>ES</TD><TD>NO</TD><TD>January 26,
2018</TD><TD>36</TR>
<TR><TD>yahoo.com</TD><TD>FR</TD><TD>OK</TD><TD>3 September
2016</TD><TD>125</TR>
<TR><TD>dell.com</TD><TD>US</TD><TD>OK</TD><TD>October 3,
2017</TD><TD>365</TR>
<TR><TD>oracle.com</TD><TD>EN</TD><TD>NO</TD><TD>3 December
2015</TD><TD>542</TR>
On 16/04/15 14:26, MOKRANI Rachid [email protected] [sed-users] wrote:
> I don't understand (in which way do you need the second file)
>
>
> The first file is generated by a script. The result is in text format.
>
> I need to create an html table with this result. The result need to be sort by the fifth column
>
> I thought creating an html mask file, and insert the result of my script in this file.
>
>
>
>
>
>> -----Message d'origine-----
>> De : [email protected] [mailto:[email protected]]
>> Envoyé : jeudi 16 avril 2015 14:21
>> À : [email protected]
>> Objet : Re: two files in one file
>>
>> in which way do you need the second file? If you just want to make the
>> file into a html table, it is easy.
>>
>>
>>
>> On 16/04/15 11:14, MOKRANI Rachid [email protected] [sed-users]
>> wrote:
>>> Hi,
>>>
>>> Using data from a text file I want to create an HTML table.
>>>
>>> I have a first file with data like : (this file is generate automatically, and the
>> line order can change )
>>> google.com FR OK 2 September 2015 21
>>> yahoo.com FR OK 3 September 2016 125
>>> dell.com US OK October 3, 2017 365
>>> oracle.com EN NO 3 December 2015 542
>>> ibm.com ES OK November 18, 2015 21
>>> sap.com ES NO January 26, 2018 36
>>> mysql.com US OK 7 Jul 2016 25
>>> etc ....
>>>
>>>
>>> My second file (second.html) is a mask in html format.
>>>
>>> ....
>>> ....
>>> <TR>
>>> <TD> Value B1 </ TD>
>>> <TD> Value B2 </ TD>
>>> <TD> Value B3 </ TD>
>>> <TD> Value B4 </ TD>
>>> <TD> Value B5 </ TD>
>>> </ TR>
>>> <TR>
>>> <TD> Value C1 </ TD>
>>> <TD> Value C2</ TD>
>>> <TD> Value C3</ TD>
>>> <TD> Value C4 </ TD>
>>> <TD> Value C5 </ TD>
>>> </ TR>
>>>
>>> <TR>
>>> <TD> Value D1 </ TD>
>>> <TD> Value D2 </ TD>
>>> <TD> Value D3 </ TD>
>>> <TD> Value D4 </ TD>
>>> <TD> Value D5 </ TD>
>>> </ TR>
>>> ...
>>> ....
>>> I need to obtain a third file like this. Data from my first file need to insert in
>> my second file for the following result.
>>> ....
>>> ....
>>> <TR>
>>> <TD> google.com </ TD>
>>> <TD> FR </ TD>
>>> <TD> OK </ TD>
>>> <TD> 2 September 2015</ TD>
>>> <TD> 21 </ TD>
>>> </ TR>
>>> <TR>
>>> <TD> yahoo.com </ TD>
>>> <TD> FR </ TD>
>>> <TD> OK </ TD>
>>> <TD> 3 September 2016</ TD>
>>> <TD> 125 </ TD>
>>> </ TR>
>>>
>>> <TR>
>>> <TD> dell.com </ TD>
>>> <TD> US </ TD>
>>> <TD> OK </ TD>
>>> <TD> October 3, 2017</ TD>
>>> <TD> 365 </ TD>
>>> </ TR>
>>> ...
>>> ....etc...
>>>
>>>
>>>
>>>
>>> Any help ?
>>>
>>> Best regards.
>>>
>>>
>>>
>>>
>>>
>>> __________________________
>>> Avant d'imprimer, pensez à l'environnement ! Please consider the
>> environment before printing !
>>> Ce message et toutes ses pièces jointes sont confidentiels et établis à
>> l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa
>> destination, toute diffusion ou toute publication, totale ou partielle, est
>> interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute
>> responsabilité au titre de ce message. This message and any attachments are
>> confidential and intended solely for the addressees. Any unauthorised use or
>> dissemination is prohibited. IFP Energies nouvelles should not be liable for
>> this message.
>>> __________________________
>>>
>>>
>>> [Non-text portions of this message have been removed]
>>>
>>>
>>>
>>> ------------------------------------
>>> Posted by: MOKRANI Rachid <[email protected]>
>>> ------------------------------------
>>>
>>
>>
>> ------------------------------------
>> Posted by: Thierry Blanc <[email protected]>
>> ------------------------------------
>>
>> --
>>
>> ------------------------------------
>>
>> Yahoo Groups Links
>>
>>
>>
> __________________________
> Avant d'imprimer, pensez à l'environnement ! Please consider the environment before printing !
> Ce message et toutes ses pièces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute responsabilité au titre de ce message. This message and any attachments are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP Energies nouvelles should not be liable for this message.
> __________________________
>
>
> ------------------------------------
> Posted by: MOKRANI Rachid <[email protected]>
> ------------------------------------
>
[Non-text portions of this message have been removed]