[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sed trouble: "\'a to á" etc



On Fri  6 Feb 2004 16:47:07 +0000(-0500), Antonio Rodriguez wrote:
> 
> #!/bin/bash
> #Trying with sed:
> #To change \'a into á and so forth
> echo "File name to process please:"
> read archivo
> cp $archivo $archivo-copia
>  
> sed -e 's/\\'a/á/g' -e 's/\\'e/é/g' -e 's/\\'{\\i}/í/g' -e 's/\\'o/ó/g' -e 's/\\'u/ú/g' -e 's/\\'A/Á/g' -e 's/\\'E/É/g' -e 's/\\'{\\I}/Í/g' -e 's/\\'O/Ó/g' -e 's/\\'U/Ú/g' -e 's/\\~n/ñ/g' -e 's/\\~N/Ñ/g' -e 's/\\"u/ü/g' -e 's/\\"U/Ü/g' -e 's/?`/¿/g' -e 's/!`/¡/g' $archivo-copia > $archivo-out

Antonio,

One thing that is wrong with this is that you have misused the shell 
quotes; you have tried to use ' inside ''. You could quote the patterns 
containing ' with "" instead of '', but you would also need to double up
the \ characters and it would be rather messy. Instead, you could avoid
shell quoting by putting the sed script in a separate file, like this:

sed -f mySedScript $archivo-copia > $archivo-out

where mySedScript contains:

s/\\'a/á/g
s/\\'e/é/g

and so on.

You can even begin the script with
#!/bin/sed -f
and invoke it like this if you wish:
mySedScript $archivo-copia > $archivo-out


-- 
Cheers,
Clive



Reply to: