f



Problem using grep command in tcl and reading multiple files

Hi All,

I am a newbie to tcl and i am having problem performing some of basic
operations using tcl.

I am having a centralized location in server where i am large number
of directories with all user logins and each directory is having some
log files with *.log extension. My requirement is to identify
directories with my login id and then go into each directory and
append all the information available in *.log files into one file.

Problem 1:

For identifying directory name with my login, i am using

exec ls | grep <USERNAME>

But it is returning "child process exited abnormally"

If i run exec ls only, it lists down all the directories.

What is wrong with "exec ls | grep <USERNAME>"

Other related question, in tcl is there any inbuilt command that can
be used to grep directories with a particular login like file command?


Problem2:

Other question is regarding opening multiple files and dumping in one
file.

I am trying following code

set file_handle [open "*.log" "r"]

But is giving error.

So i think i should do it like

set list_dir [glob *.log]
foreach file_name $list_dir {
set file_handle [open $file_name "r"]
lappend list_var [reads $file_handle]
close $file_handle
}

Is this the only way to do it, is there any shortcut to do it like in
unix we can do "cat *.log > filename" in tcl?

Thanks


0
5/25/2011 2:16:34 PM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

1 Replies
497 Views

Similar Articles

[PageSpeed] 5

At Wed, 25 May 2011 07:16:34 -0700 (PDT) sunny <techbie.wordpress@gmail.com> wrote:

> 
> Hi All,
> 
> I am a newbie to tcl and i am having problem performing some of basic
> operations using tcl.
> 
> I am having a centralized location in server where i am large number
> of directories with all user logins and each directory is having some
> log files with *.log extension. My requirement is to identify
> directories with my login id and then go into each directory and
> append all the information available in *.log files into one file.
> 
> Problem 1:
> 
> For identifying directory name with my login, i am using
> 
> exec ls | grep <USERNAME>
> 
> But it is returning "child process exited abnormally"
> 
> If i run exec ls only, it lists down all the directories.
> 
> What is wrong with "exec ls | grep <USERNAME>"
> 
> Other related question, in tcl is there any inbuilt command that can
> be used to grep directories with a particular login like file command?

look at the glob and regexp commands:

set username heller
glob -nocomplain "*${username}*

or

foreach f [glob -nocomplain *] {
  if {[regexp {some-USERNAME-pattern} $f] > 0} {
    process $f
  }
}

(some-USERNAME-pattern would be a regexp pattern expression and the
procedure 'process' would be some code that does something with the
matched filename.)

> 
> 
> Problem2:
> 
> Other question is regarding opening multiple files and dumping in one
> file.
> 
> I am trying following code
> 
> set file_handle [open "*.log" "r"]

open does not take a wildcard!

> 
> But is giving error.
> 
> So i think i should do it like
> 
> set list_dir [glob *.log]
> foreach file_name $list_dir {
> set file_handle [open $file_name "r"]
> lappend list_var [reads $file_handle]
> close $file_handle
> }
> 
> Is this the only way to do it, is there any shortcut to do it like in
> unix we can do "cat *.log > filename" in tcl?

The '*.log' is processed by shell wildcard expansion.  Cat merely takes
multiple arguments.

proc cat {args} {
  set result {}
  foreach f $args {
    set infp [open $f r]
    append  result [read $infp]
    close $infp
  }
  return $result
}

set alllogs [eval cat [glob *.log]]



> 
> Thanks
> 
> 
>                                                                                                                                 

-- 
Robert Heller             -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments


                         
0
heller (3031)
5/25/2011 3:14:42 PM
Reply:

Similar Artilces:

Problems using the tcllib package tie in Windows and tcl file commands
I am having problems using the tcllib package tie in Windows but it is actually a problem with the tcl file commands. I am using Tcl 8.5.11 If from one tk console I create a tie to an array it saves a file and updates it correctly when array changes ... (bin) 49 % package require tie 1.1 (bin) 50 % array set data {a 2 b 4 c 5.423} (bin) 51 % ::tie::tie data -save file "D:/Data/temp/data.dat" tie1If I then from a second tk console I attempt to access the data from this file it works the first time (bin) 49 % package require tie 1.1 (bin) 50 % array set data {} (bin) 51 % ::tie::tie data file "D:/Data/temp/data.dat" tie1 (bin) 52 % array get data a 2 b 4 c 9.423When I update the array in the first console it updates the file correctly, however ... .... when I come to access the updated data in the second console it throws an error. (bin) 53 % ::tie::tie data file "D:/Data/temp/data.dat" error renaming "D:/Data/temp/data.dat.new" to "D:/Data/temp/data.dat": permission deniedIt seems to be having problems when it comes to overwite the data file with the shortened datafile from the cache. I have tried "untying" the arrays manually and overrwriting files from the console and this seems to work fine so I can't understand why it doesn't do the same thing from inside the script. Rachel Sorry, I guessing that I ought to release the sending interp with an untie at the end of ...

How to read a file using TCL
Hi, I am a new bee to TCL. I want to write a script that opens the file and reads it and prints to screen. I have tried the below. But doesn't works. set INFILE [open "temp" a+] set data [read $INFILE] set data [split $data "\n"] foreach line $data { puts $line } -Regards Swaroop Kumar Tata On 14 Mai, 10:39, Swaroop <swaroop.t...@gmail.com> wrote: > Hi, > I am a new bee to TCL. I want to write a script that opens the > file and reads it and prints to screen. I have tried the below. But > doesn't works. > > set INF...

Tcl+incr Tcl debuggers to use on command line?
Hi, Does anyone know of incr Tcl supported debuggers that work on command line? That is, without needing bundling with IDEs? Thanks On 10/11/14, 9:46 PM, kenneth.bull@gmail.com wrote: > Hi, > > Does anyone know of incr Tcl supported debuggers that work on command line? > That is, without needing bundling with IDEs? Well, the debugger in ActiveState's TDK does not need a bundled IDE and it works with [incr Tcl] -- but it is a GUI application not a command line one. -- +------------------------------------------------------------------------+ | Gerald W. L...

Sourcing a TCL file from within a tcl file
I am a newbie which I am sure I don't need to state :) I am trying to create a variable with a TCL file that will source another tcl file when I type the variable name something like this if I enter A through my keyboard then source a.tcl Can someone show me how to do this thanks guy On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > I am a newbie which I am sure I don't need to state :) > > I am trying to create a variable with a TCL file that will source > another tcl file when I type the variable name > > something like this > > if I enter A through my keyboard =A0then source a.tcl > > Can someone show me how to do this > > thanks > guy What you are asking is not hard. Will your program have a graphical user interface? Aric On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote: > On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > > > I am a newbie which I am sure I don't need to state :) > > > I am trying to create a variable with a TCL file that will source > > another tcl file when I type the variable name > > > something like this > > > if I enter A through my keyboard =A0then source a.tcl > > > Can someone show me how to do this > > > thanks > > guy > > What you are asking is not hard. =A0Will your program have a graphical > user interface? > > Aric no I am just using this script...

How to read an Excel file using TCL Scripts
Hi all, I have an excel file test.xls.It is created manually and few values are added manually. I Want to read each column of the excel and store in some variable using TCL Scripts. I went thro lot of examples but nothing related to above requirement I found. Please give suggestions or links where this code is given. Thanks in Advance, RAGHU On 25 =D0=BD=D0=BE=D1=8F, 12:55, RAGHU <ragh...@gmail.com> wrote: > I Want to read each column of the excel and store in some variable > using TCL Scripts. Open http://wiki.tcl.tk/tcom and search for "Extract some cells from an Excel file". On 25 Nov., 10:55, RAGHU <ragh...@gmail.com> wrote: > Hi all, > > I have an excel file test.xls.It is created manually and few values > are added manually. > > I Want to read each column of the excel and store in some variable > using TCL Scripts. > > I went thro lot of examples but nothing related to above requirement I > found. > > Please give suggestions or links where this code is given. > > Thanks in Advance, > RAGHU This question was here 1 or two months ago. Check the mailing list or search in the wiki. hi Raghu, Save the excel file into csv format... thsi will then give you a comma separated values... since it is separated by comma you can use the tcl comman to "split". split "\n" string to split per row.. split "," string to split per co...

TCL/PHP/XML problem: I need to convert an XML file into a TCL list
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: [TCL] set contents [read $fileID [file size ${fileName}.xml]]; close $fileID if {![string equal $switch -body]} { # ONLY DO THIS IF THE XML CONTENTS CONTAIN NO BODY - WILL UPGRADE AT A LATER DATE 11/24/2006 - PHIL global serverName if {![info exists serverName]} { global env source ./cgi_globals.tcl global serverName } if {[string length [info procs {URL_ENCODE}]] == 0} { source...

Read multiple .wav files using single wavread command
Hi, i want to read multiple .wav files using single wavread command and play it in matlab.... Thank you On 11/7/2012 6:00 AM, Praveen wrote: > Hi, > > i want to read multiple .wav files using single wavread command and play it in matlab.... > > Thank you > hi Praveen; I do not know if Matlab can read more than one file in one call since waveread supports one file at a time. What is wrong with reading one file at a time? using a 'for' ? What must all the files be read in one call? --Nasser "Nasser M. Abbasi" <nma@12000.org> wrote in message <k7dk8q$4ep$1@speranza.aioe.org>... > On 11/7/2012 6:00 AM, Praveen wrote: > > Hi, > > > > i want to read multiple .wav files using single wavread command and play it in matlab.... > > > > Thank you > > > > > hi Praveen; > > I do not know if Matlab can read more than one file in one call since > waveread supports one file at a time. > > What is wrong with reading one file at a time? using a 'for' ? > What must all the files be read in one call? > > --Nasser Hi Nasser, Actually i want to play some 150 small duration wav files at a time one after other.... so instead of using wavread 150 times... i wanted to know like ...is it possible to put wavread in a for loop so that i can play files using single command..... Thank you > Actuall...

Problem using thread command in Tcl 8.6.0
Hi, I have an external program (let's call it calculate.exe), that will take a long time to run, but can only use one CPU. (I am using Win7). So I am trying the use the thread command in tcl 8.6 to run two jobs simultaneously to save time. Each job for the calculate.exe program needs to run in a separate directory. This is what I do >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> set t1 [thread::create] set t2 [thread::create] thread::send -async $t1 "source run01.tcl" result thread::send -async $t2 "source run02.tcl" result for {set i 0} {$i < 2} {incr i} { vwait result } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> This is run01.tcl >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cd c:/run01 exec calculate.exe < input.txt >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> This is run02.tcl >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cd c:/run02 ...

Problem using command line argument with grep in plot file
Hello, I hope someone can assist me with this. I am plotting a file based on condi= tional data. To accomplish this, I'm using grep when plotting the file. The= path of the data file is dynamic so I'm passing it in the command line. I'= m having trouble passing the entire file with path to grep. Here's an examp= le: I am calling gnuplot as follows: gnuplot -e "result_path=3D'/test/'" GNU.plt GNU.plt has plot '<grep -E "System/CPU/System/percent.*655291" '.result_path.'Metrics.t= xt'. using 2:4 every ::2 with lines This doesn't work because result_path is not being evaluated.=20 If I change GNU.plt to the following, then it works: plot result_path.'Metrics.txt' using 2:4 every ::2 with lines So I know result_path works, but not sure how to put it in the middle of th= e "grep" command.=20 thanks, Marcelo Marcelo Jara wrote: > Hello, > > I hope someone can assist me with this. I am plotting a file based on > conditional data. To accomplish this, I'm using grep when plotting the > file. The path of the data file is dynamic so I'm passing it in the > command line. I'm having trouble passing the entire file with path to > grep. Here's an example: > > I am calling gnuplot as follows: > > gnuplot -e "result_path='/test/'" GNU.plt > > > GNU.plt has...

l'C program executing from a tcl script with pipe opened using open command in Tcl
Hi all, I wanted to communicate with a C program from a Tcl script.. The test code i have written is below Both the 'C' program and Tcl script are located in the same directory. The 'C' program is below. I have named it CTCL.C #include<stdio.h> #include<string.h> int main() { int i; char c[30]; printf("Reading..."); scanf("%s",c); printf("String read is :%s\n",c); fflush(stdout); return 0; } I have compiled the program with the command cc CTCL.C -o ctcl So the executable was generated with the name 'ctcl' The Tcl script...

How can I use tcl to read files written in GBK or GB18030 encoding?
I know that Tcl has quite a large list of encodings that it supports. However, I've a request for guidance by someone who needs to read files using either GBK or GB18030 (I think these are alternate names for the same encoding...). Has anyone worked out what one needs to do for this? On 31 Jan., 16:26, "Larry W. Virden" <lvir...@gmail.com> wrote: > I know that Tcl has quite a large list of encodings that it supports. > However, I've a request for guidance by someone who needs to read > files using either GBK or GB18030 (I think these are alternate names >...

read file in tcl
how to read or call a file in tcl ? davidw@dedasys.com (David N. Welton) wrote in message news:<873cg837s7.fsf@dedasys.com>... > prowarcraftplayer@yahoo.com (K Zewi) writes: > > > how to read or call a file in tcl ? > > 'call' a file? > > Reading a file can be done with the 'read' command: > > set fl [open "somefile"] > set data [read $fl] > > is a simple way to do it. You want to look at the documents for those > commands, and maybe 'fconfigure' if you want to read a binary file. i still can't read ...

how to read file in tcl
in the condition that giving some coordinate of polygon in a directory and i have to read these file without using the command create poly how to call these file from the directory? In article <36940419.0308110031.66a5cd1@posting.google.com>, K Zewi <prowarcraftplayer@yahoo.com> wrote: >in the condition that >giving some coordinate of polygon >in a directory and i have to >read these file without using >the command create poly >how to call these file >from the directory? Did you ever get the help you sought? My guess is that readers found your question...

Problem using hyperhelp
As those who have answered various of my questions know, I have problems finding information known to exist "somewhere" in the man pages. I think I have a handle on how I want to retrieve what *I* consider the "relevant" hits. Now comes the problem displaying the retrieved information. As the man pages I'm using are in HTML (see http://www.tcl.tk/man/) I started looking for Tcl/Tk packages that could display HTML files. I came across "hyperhelp". It is apparently included in the ActiveState distribution which I use. At least its man page is available in the Help system. That page gives an example of usage. As is frequently the case - it does *NOT* work as given. The routine problem is missing "package require" statements (though often given elsewhere in the page). A Google search and roving the wiki indicated that at least package require Tk package require Iwidgets package require Itk are required. I still get invalid command name "hyperhelp" .. On 29 jan, 09:03, Richard Owlett <rowl...@atlascomm.net> wrote: > As those who have answered various of my questions know, I have problems > finding information known to exist "somewhere" in the man pages. I think > I have a handle on how I want to retrieve what *I* consider the > "relevant" hits. > > Now comes the problem displaying the retrieved information. As the man > pages I'm using are in HTML (seehttp://w...

tcl-gaul: Genetic Algorithms for Tcl. (Tcl package)
This is an announcement for a relatively new Tcl project: tcl-gaul Tcl-gaul is a Tcl extension for genetic/evolutionary algorithm processing.It relies on the GAUL library: http://gaul.sourceforge.net/ * A genetic algorithm (GA) is a search technique used in computing to find exact or approximate solutions to optimization and search problems. Genetic algorithms are categorized as global search heuristics. They are a particular class of evolutionary algorithms that use techniques inspired by evolutionary biology such as inheritance, mutation, selection, and crossover. For an introduction to genetic algorithms visit: http://gaul.sourceforge.net/intro.html Platform: Linux (GAUL library dependency) Home page: http://sourceforge.net/projects/tcl-gaul/ Man page: http://tcl-gaul.sourceforge.net/ Author: Alexandros Stergiakis alsterg ...

tcl-pam: PAM authentication for Tcl (Tcl package)
This is an announcement for a relatively new Tcl project: tcl-pam Tcl-pam is a Tcl interface to the PAM* service of Linux. It provides a Tcl package that allows Tcl scripts to use PAM to authenticate users and programs. It relies on linux-pam library: http://www.kernel.org/pub/linux/libs/pam/ * PAM (Pluggable Authentication Modules): A mechanism to integrate multiple low−level authentication schemes into a high−level application programming interface (API). This enables programs that rely on authentication to be written independently of the underlying authentication scheme. Platform: Linux Home page: http://sourceforge.net/projects/tcl-pam/ Man page: http://tcl-pam.sourceforge.net/ Author: Alexandros Stergiakis alsterg ...

Reading a tcl file in C
I have a tcl configure file (a list of variables with values and comments) that I wish to read into an array in C (or better yet, Objective-C). Does anyone have any suggestions of how to do this, or have any public-domain or GPL code that does this? randall.h.wood@gmail.com wrote: > I have a tcl configure file (a list of variables with values and > comments) that I wish to read into an array in C (or better yet, > Objective-C). Does anyone have any suggestions of how to do this, or > have any public-domain or GPL code that does this? Can you give us a short example of what this ...

read an XML file in TCL
Hello I am looking to read an XML file into my TCL program and extract information. How do we read an XML file in TCL? Are there man pages that describe these? Thanks krithiga one way is: http://wiki.tcl.tk/tdom another (and faster, but should be used only for valid stuff) is http://wiki.tcl.tk/11020 Torsten Edler wrote: > another (and faster, but should be used only for valid stuff) is > I'm curious as to this assertion that the shallow regexp parser is faster than tdom, I would have expected things to be the other way around. Do you have a benchmark? Were you testing...

Using TCL files in Python ?
I am reasonably new to programming in Python. [Using LINUX] Up until now I have been using GUI widgets supplied by 'Tkinter' but starting to realise that Tkinter have limited widgets. I have been given the lead that I should look at other sources for GUI widgets - namely TCL. I have just done a search for 'tcl' files on my 'Fedora 3' installation and find I have available: Tix8.1 Tcl8.4 Tk8.4 I have never used TCL code under Python so I assume I can use widgets from any of these providers ? Where is a good resource I can use to help understand how to use TCL...

Read block of file in Tcl
Hi, I have an input file in the following format: ******************************** Name1 Name2 Row1 DEF 001 Row2 ABC DEG 003 Row3 EW EW 002 Row4 FF 0012 Row1 ADEF 1001 Row2 ARBC DEG 2003 Row3 EWW EW 0302 Row4 AB 0112 Name1 Name2 Row1 DSDEF 001 Row2 ABVC DEG 003 Row3 EDW EW 002 Row4 FVF 0012 Row1 AF 1001 Row2 ACRBC DEG 2003 Row3 ESWW EW 0302 Row4 AEB 0112 **************************************** I have to read this file and --> if I get "Name1" in any of the line, then I have to read the block of file from "Name1" to the first occurrance of "Row4". --> I...

tcl code to read an image and write tcl code?
Does anyone know where I can find a tcl proc that would take an image, say a gif, and output pure tcl code that I could paste into a program? I saw something about a unix program that did something with mimes but I'm on windows. In article <4403BC94.447A7341@rocketship1.com>, Eric Taylor <et2@rocketship1.com> wrote: > > >Does anyone know where I can find a tcl proc >that would take an image, say a gif, and output >pure tcl code that I could paste into a program? > >I saw something about a unix program that did >something with mimes but I'm on wi...

Will tcl 9 use epoll or kqueue for tcl?
curious http://luvit.io/ also check this out for web stuff done in lua but perhaps tcl can steal nice ideas On Wednesday, January 2, 2013 3:22:02 PM UTC-8, gavino_himself wrote: > curious > > > > http://luvit.io/ also check this out for web stuff done in lua but perhaps tcl can steal nice ideas cherokee uses them so gota be ast for events and cherokee outperforms nginx ...

Dose there any tcl script to translate an file with embedded tcl
Hi I need to generate some big file, but there are rules for generate these files Ex . ============================== Start input a [0] wire input a [1] wire .. .. .. .. input a [1000] wire End ================================= Dose there any tcl script can help to translate a file with embedded tcl script into a new file For example this is a source file ======================== Start * set i 0 * for { set i 0 } { $i < 1000 } { incr i } { * puts input a [$i] wire * } End ========================== After Translate ======================= Start input a [0] wire input a [1] wire .. .. ...

How to open a logical partition and read all of its file using windows function ReadFile() ? Question How to open a logical partition and read all of its file using windows function ReadFile() ?
Hii In my application , wanna copy all files from one partition to another partition. First I copied a file that I taken default and copied to another partition. The above operation is done by using the control code "FSCTL_GET_RETRIEVAL_POINTERS". The clusters used are read and wrote into destination volume using readfile() and writefile() windows functions. Now I gotta copy all files..... So how to proceed ....?? Thanking you. On Sat, 13 Jun 2009 09:37:42 -0700 (PDT), krish <krishnampkkm@gmail.com> wrote: >Hii > >In my applicatio...

Web resources about - Problem using grep command in tcl and reading multiple files - comp.lang.tcl

Multiple sequence alignment - Wikipedia, the free encyclopedia
A multiple sequence alignment (MSA) is a sequence alignment of three or more biological sequences , generally protein , DNA , or RNA . In many ...

Man stabbed multiple times, woman arrested
A man is fighting for life after being stabbed multiple times in Rosebud West on Saturday.

Windows 10 Mobile Update: Multiple evidences indicate March 2016 arrival
Microsoft has consistently delayed the arrival of the Windows 10 Mobile update since December 2015, but fresh information indicate that the update ...

Sydney shooting: Police, ambulances rush to multiple shooting at Ingleburn
Police are responding to reports of a multiple shooting at Ingleburn in Sydney's south-west.

Sydney shooting: Police, ambulances rush to multiple shooting at Ingleburn
Police are responding to reports of a multiple shooting at Ingleburn in Sydney's south-west.

Newly released multiple angle video and photos show Google’s self-driving car accident [Video]
A new video with multiple angles and new pictures of the Google’s self-driving car hitting a bus last week and its aftermath have been released ...

Multiple iOS apps found to be harvesting Snapchat user credentials
... them and change their passwords on the social media platform as soon as possible. New discoveries revealed today point to the fact that multiple ...

Fire officials: Boarding house blaze kills multiple victims
ATLANTA (AP) — An Atlanta fire spokesman says a fire has killed multiple victims at a boarding house.

Suicide Squad: Margot Robbie Tried On Multiple Versions Of Harley Quinn Costume Including Court Jester ...
When the first images of Margot Robbie's Arkham-inspired Harley Quinn from Suicide Squad hit the [...]

Science Says: Video Games May Improve Cognitive Abilities In Multiple Sclerosis Patients
... a newly published study claims that some video games may actually be helpful for the more than 2 million people around the world with Multiple ...

Resources last updated: 3/13/2016 10:46:15 AM