|
|
 |
 |
 |
 |
TCL(Tool Command Language) Scripting
|
 |
 |
 |
 |
 |
 |
 |
 |
exec sort tab separator Question
Hi all, I've been looking around for some answers to this... it is certainly a recurrent question ... sorry for this... I wanted to sort a zipped file and explicitly specify that the field separator is a tab, but I can't find a way to reproduce it in a proper tcl proc. It is even tricky to do it directly in a shell since you have to a control+v and then use the tab key... set Cmd "exec gunzip -cd $FileIn | sort -t\"\t\" -k1,1 -k3,3r" eval $Cmd or set FS "\t" set Cmd "exec gunzip -cd $FileIn | sort -t\"$FS\" -k1,1 -k3,3r" set Cmd "exec gunzip -cd $FileIn | sort -t\"\$FS\" -k1,1 -k3,3r" does not work... I have tried several combination but I think in the best case the \t is replaced by several "blank". Anybody has answer and some explanation so maybe I will not ask anymore this question on quoting not quoting... ;-) I really appreciate explanations... and stopping "the try and see if it crashes or not and add another quote or" ... :-) Many thanks in advance Jeannot
On 9 mei, 10:59, Jeannot <jean.mul@igbmc.u-strasbg.fr> wrote:
> Hi all, > I've been looking around for some answers to this... it is certainly a > recurrent question ... sorry for this... > I wanted to sort a zipped file and explicitly specify that the field > separator is a tab, but I can't find a way to reproduce it in a proper > tcl proc. It is even tricky to do it directly in a shell since you > have to a control+v and then use the tab key... > set Cmd "exec gunzip -cd $FileIn | sort -t\"\t\" -k1,1 -k3,3r" > eval $Cmd > or > set FS "\t" > set Cmd "exec gunzip -cd $FileIn | sort -t\"$FS\" -k1,1 -k3,3r" > set Cmd "exec gunzip -cd $FileIn | sort -t\"\$FS\" -k1,1 -k3,3r" > does not work... > I have tried several combination but I think in the best case the \t > is replaced by several "blank". > Anybody has answer and some explanation so maybe I will not ask > anymore this question on quoting not quoting... ;-) > I really appreciate explanations... and stopping "the try and see if > it crashes or not and add another quote or" ... :-) > Many thanks in advance > Jeannot
The problem is that your command goes through several different layers each wanting desperately to interpret the tab (and spaces and ...). I notice you store it all in the variable Cmd and then do eval. When I do, instead: set r [exec sort -t\t ...] it seems to work fine. That may be problematic with a varying list of options though Regards, Arjen
On 9 mai, 11:16, Arjen Markus <arjen.mar@wldelft.nl> wrote:
> On 9 mei, 10:59, Jeannot <jean.mul @igbmc.u-strasbg.fr> wrote: > > Hi all, > > I've been looking around for some answers to this... it is certainly a > > recurrent question ... sorry for this... > > I wanted to sort a zipped file and explicitly specify that the field > > separator is a tab, but I can't find a way to reproduce it in a proper > > tcl proc. It is even tricky to do it directly in a shell since you > > have to a control+v and then use the tab key... > > set Cmd "exec gunzip -cd $FileIn | sort -t\"\t\" -k1,1 -k3,3r" > > eval $Cmd > > or > > set FS "\t" > > set Cmd "exec gunzip -cd $FileIn | sort -t\"$FS\" -k1,1 -k3,3r" > > set Cmd "exec gunzip -cd $FileIn | sort -t\"\$FS\" -k1,1 -k3,3r" > > does not work... > > I have tried several combination but I think in the best case the \t > > is replaced by several "blank". > > Anybody has answer and some explanation so maybe I will not ask > > anymore this question on quoting not quoting... ;-) > > I really appreciate explanations... and stopping "the try and see if > > it crashes or not and add another quote or" ... :-) > > Many thanks in advance > > Jeannot > The problem is that your command goes through several different > layers each wanting desperately to interpret the tab (and spaces > and ...). > I notice you store it all in the variable Cmd and then do eval. > When I do, instead: > set r [exec sort -t\t ...] > it seems to work fine. That may be problematic with a varying list of > options though > Regards, > Arjen
Thanks, I am not sure I understand all but then since it simply using \t was working for you I have tried to protect mine since there is another layer... and it works!! so the following is fine with me: set Cmd "gunzip -cd $FileIn | sort -t\\t -k1,1 -k3,3r | gzip -9 > $FileOut" Thanks Jeannot
> Thanks, > I am not sure I understand all but then since it simply using \t was > working for you I have tried to protect mine since there is another > layer... and it works!! > so the following is fine with me: > set Cmd "gunzip -cd $FileIn | sort -t\\t -k1,1 -k3,3r | gzip -9 > > $FileOut" > Thanks > Jeannot
This may probably help to understand it better: % set a \"\t\" " " % set a \\t \t bash or whatever shell you are using expects \t (a slash character and a t character) from you and \\t does it by escaping \ At the same time \"\t\" does also exactly what is supposed to do - it's being translated by tclsh into " " (spaces meaning a tab character) so \t never reaches bash. Cheers, Pavel.
"pn8830" <pnovozhi @gmail.com> wrote in message news:1178723685.959599.66590@l77g2000hsb.googlegroups.com...
>> Thanks, >> I am not sure I understand all but then since it simply using \t was >> working for you I have tried to protect mine since there is another >> layer... and it works!! >> so the following is fine with me: >> set Cmd "gunzip -cd $FileIn | sort -t\\t -k1,1 -k3,3r | gzip -9 > >> $FileOut" >> Thanks >> Jeannot > This may probably help to understand it better: > % set a \"\t\" > " " > % set a \\t > \t > bash or whatever shell you are using expects \t (a slash character and > a t character) from you and \\t does it by escaping \ > At the same time \"\t\" does also exactly what is supposed to do - > it's being translated by tclsh into " " (spaces meaning a tab > character) so \t never reaches bash.
Nope. Tcl never translates tab chars to spaces. The shell may display a tab char as a space and when a string is turned to a list tabs are just treated as white space. However, notice: % set a \"\t\" " " % string length $a 3
Roy Terry wrote: > "pn8830" <pnovozhi @gmail.com> wrote in message > news:1178723685.959599.66590@l77g2000hsb.googlegroups.com... >>> Thanks, >>> I am not sure I understand all but then since it simply using \t was >>> working for you I have tried to protect mine since there is another >>> layer... and it works!! >>> so the following is fine with me: >>> set Cmd "gunzip -cd $FileIn | sort -t\\t -k1,1 -k3,3r | gzip -9 > >>> $FileOut" >>> Thanks >>> Jeannot >> This may probably help to understand it better: >> % set a \"\t\" >> " " >> % set a \\t >> \t >> bash or whatever shell you are using expects \t (a slash character and >> a t character) from you and \\t does it by escaping \ >> At the same time \"\t\" does also exactly what is supposed to do - >> it's being translated by tclsh into " " (spaces meaning a tab >> character) so \t never reaches bash. > Nope. Tcl never translates tab chars to spaces. The shell > may display a tab char as a space and when a string is turned to > a list tabs are just treated as white space. However, notice: > % set a \"\t\" > " " > % string length $a > 3
in addition, exec in tcl does *NOT* go through bash or any other shell, so you don;t need *shell* quoting, just the tcl quoting so -t$FS should suffice, by adding the \" the sort command was getting the actual quote chars as part of it's input (not what was intended. Bruce
> Nope. Tcl never translates tab chars to spaces. The shell > may display a tab char as a space and when a string is turned to > a list tabs are just treated as white space. However, notice:
Yes. That's exactly what I meaned. I just could not insert tab character into the newsgroup message ;)
On 9 mai, 21:50, pn8830 <pnovozhi@gmail.com> wrote: > > Nope. Tcl never translates tab chars to spaces. The shell > > may display a tab char as a space and when a string is turned to > > a list tabs are just treated as white space. However, notice:
Thanks that is exactly what I understood ;-) Good things to know. Thanks for the several explanations. Jeannot
|
 |
 |
 |
 |
|