Verify if a string is a valid UTF-8 string? [SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#16 Post by don570 »

It's possible to do stream editing (SED) on one line by using the semi-colon.
It might speed up the script as well.

Code: Select all


sed -i "s%<b>%%g;" /tmp/report-video_
sed -i "s%</b>%%g" /tmp/report-video_

sed -i "s%<b>%%g;s%</b>%%g" /tmp/report-video_



User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#17 Post by Argolance »

Hello don570,
Yes, it is much better! This is the way we learn, little by little... Thank you! I will have to revise most of the scripts I made, because since the first one, I learnt many small tricks like this one: for sure, they will be less heavy and faster! :wink:

Cordialement.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#18 Post by Argolance »

Bonjour,
Following the code lines above, I replaced:

Code: Select all

func () {
sed -i "s%<b>%%g" /tmp/report-video_
sed -i "s%</b>%%g" /tmp/report-video_
sed -i "s%millimeters%$(gettext 'millimeters')%g" /tmp/report-video_
sed -i "s%planes%$(gettext 'planes')%g" /tmp/report-video_
sed -i "s%pixels%$(gettext 'pixels')%g" /tmp/report-video_
}
export -f func

sed -i "s%millimeters%$(gettext 'millimeters')%g" /tmp/report-video
sed -i "s%planes%$(gettext 'planes')%g" /tmp/report-video
sed -i "s%pixels%$(gettext 'pixels')%g" /tmp/report-video
with:

Code: Select all

func () {
sed -i "s%<b>%%g";"s%</b>%%g";"s%millimeters%$(gettext 'millimeters')%g";"s%planes%$(gettext 'planes')%g";"s%pixels%$(gettext 'pixels')%g" /tmp/report-video_
}
export -f func

sed -i "s%millimeters%$(gettext 'millimeters')%g";"s%planes%$(gettext 'planes')%g";"s%pixels%$(gettext 'pixels')%g" /tmp/report-video
And I got:
sed: no input files
/usr/sbin/2P_report-video: line 127: s%planes%niveaux%g: command not found
/usr/sbin/2P_report-video: line 127: s%pixels%pixels%g: command not found
sed: no input files
sh: line 1: s%</b>%%g: No such file or directory
sh: line 2: s%millimeters%millimètres%g: command not found
sh: line 3: s%planes%niveaux%g: command not found
sh: line 4: s%pixels%pixels%g: command not found
EXIT="OK"
Script completed hit RETURN to close window.
:shock: :oops:

Cordialement.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#19 Post by L18L »

Argolance wrote:...Following the code lines above, I replaced:..

Pas "tres" exactement ... :wink:

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#20 Post by amigo »

The syntax is like this:

Code: Select all

sed -i -e '....' -e '...' filename
or:

Code: Select all

sed -i -e '....' \
-e '...' \
-e '...' filename

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#21 Post by L18L »

or:
sed -i -e "....;...;..." filename

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#22 Post by Argolance »

Pas "tres" exactement ...
Pas exactement du tout! Sorry!

Code: Select all

func () {
sed -i "s%<b>%%g;s%</b>%%g;s%millimeters%$(gettext 'millimeters')%g;s%planes%$(gettext 'planes')%g;s%pixels%$(gettext 'pixels')%g" /tmp/report-video_
}
export -f func

sed -i "s%millimeters%$(gettext 'millimeters')%g;s%planes%$(gettext 'planes')%g;s%pixels%$(gettext 'pixels')%g" /tmp/report-video
As we are used to say in French: "I had no eyes in front of holes"
This is very much better this way! :D
Thank you!

Cordialement.

Post Reply