Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem using cut command in tcl

Status
Not open for further replies.

naru21

Technical User
May 24, 2002
13
US
Hi,
when i try to use the cut command in tcl it didnt work
exec cut -f1-3 -d'|' file

but it works fine in unix. I think when tcl see '|' it might be taking as special character.

I have data file some thing like this
file:
07/25/2002 00:30|Type|Application|Group
07/25/2002 00:33|Type|Application|Group
07/25/2002 00:35|Type|Application|Group
07/25/2002 00:37|Type|Application|Group


any help is appreciated
thanks
Naru
 
Yes, | is a pipe indicator for Tcl.

You need to protect the char by \:
Code:
exec cut -f1-3 -d'\|' file
or the argument by { and }:
Code:
exec cut -f1-3 {-d'|'} file
(not tested)

But you can do all that with Tcl commands.
Additionaly that would be more portable:
Code:
  # create test file
  set fp [open myfile w]
  puts -nonewline $fp "07/25/2002 00:30|Type|Application|Group
07/25/2002 00:33|Type|Application|Group
07/25/2002 00:35|Type|Application|Group
07/25/2002 00:37|Type|Application|Group"
  close $fp
  # reopening file, get first three fields of each line
  set fp [open myfile]
  while {![eof $fp]}   {
    gets $fp line
    set items [split $line |]
    puts [lrange $items 0 2]
  }
  close $fp
The split command will split each line at the | separator and build a list of all fields.
The lrange commmand will select the first three fields.

Good luck

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top