[LUGOS] Zacetniske tezave s sedom

Stojan Rancic stojan at aufbix.org
Sat Sep 22 07:40:33 CEST 2007


Bostjan Janezic wrote:
> Grega Fajdiga je rekel(la):
>> sed -e s/charset=Windows-1252/charset=Windows-1250/ *.htm
>>
>> Namesto zamenjave, mi prek zaslona zbrzi vsebina vseh datotek
>> html, zamenjave pa ne naredi.
>>
>> Kaj pocnem narobe?
> Takole pravi eno navodilo za sed:
> 
> If you want it to make changes for every word, add a "g" after the last delimiter
> and use the work-around:
> 
>     sed 's/[^ ][^ ]*/(&)/g' <old >new
> Pozabil si "g". :)

Niti ne.. Sed kot tak ti bo output svojega dela vrgel na stdout, od 
koder ga moras potem ustrezno redirectati (temporary datoteke, 
preimenovanje,.), kot naprimer v spodnjem primeru:

#!/bin/sh

for file in $(grep -il "Hello" *.txt)
do
sed -e "s/Hello/Goodbye/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done

.. ce pa hoces zadevo resiti elegantno, lahko pa uporabis Perlov in-line 
replacement:

perl -pi -e 's/charset=Windows-1252/charset=Windows-1250/' *.htm

..

lp, Stojan


More information about the lugos-list mailing list