- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Microsoft
- >
- Re: Need help on TCL scripts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 06:47 AM
тАО09-27-2009 06:47 AM
Need help on TCL scripts
can I use sed operation in tcl scripts ?
Need to get line 20 to line 60.
Pattern might be vary.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 06:52 AM
тАО09-27-2009 06:52 AM
Re: Need help on TCL scripts
Since TCL scripts are whitespace-delimited strings terminated by a newline or semicolon, they are appropriate text files for use by standard tools like 'sed', 'awk', Perl, etc.
As always, when in doubt, TRY IT! :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 07:19 AM
тАО09-27-2009 07:19 AM
Re: Need help on TCL scripts
> Need to get line 20 to line 60. Pattern might be vary.
I suppose that that really was your question. You can do:
# sed -ne '20,60p' file
THe '-n' turns off printing. The '-e' says the script follows. The '20.60p' says from line-20 (one-relative) through line-60 print ('p').
If you wanted to do the same not knowing line-numbers but knowing patterns that mark the lines you want, you could do:
# sed -ne '/pattern1/,/pattern2/p' file
Notice that the regular expression to match is enclosed in forward slashes, with a common again signifying a range.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 08:16 AM
тАО09-27-2009 08:16 AM
Re: Need help on TCL scripts
but wondering, in pervious perl which you had provide,
#!/usr/bin/perl
use strict;
use warnings;
my ( @first, @second, $slot, $n );
while (<>) {
next if /^===/;
if (m{^\s*\d}) {
@first = split;
next;
}
if (m{^slot}) {
@second = split;
$slot = shift @second;
( $slot = shift @second ) =~ s/://;
}
if ( m{^\s*$} or eof ) {
for ( $n = 0; $n < @first; $n++ ) {
print $slot, '/', $first[$n],' ',$second[$n],"\n";
}
}
}
1;
I need to check if $second[$n] contain k or m, if contain k, then $second[$n], exclude the string k, and multiplier 1000, if contain m, then exclude the string m, and multiplier 1000000, if not contain k either m, print, any suggestion ?
originally, I would like to combine tcl with expect module to get the input, (perl in windows do not have expect), then call perl script to handle to reformat, then called cygwin to process the numbers to re-print the result,
don't know if there have any other quick way which not to install too many extra application on windows system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 08:29 AM
тАО09-27-2009 08:29 AM
Re: Need help on TCL scripts
You can access all the traditional regexps in TCL, plus AREs, which include some extra definitions.
To read in lines 20 to 60 in a script and process each line using patterns you could easily:
set fd [open "file_name" "r"]
# Slurp file contents
set lines [split [read $fd] "\n"]
close $fd
# Get lines 20 - 60 inclusive
set lines [lrange $lines 20 60]
# Operate on lines
foreach line $lines {
# Use regexp to match lines by pattern
# Use regsub to substitute by pattern
}
The exact syntax and regexp rules are described here:
http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm
Kind regards,
Kobylka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 08:35 AM
тАО09-27-2009 08:35 AM
Re: Need help on TCL scripts
> hmm, due the customer enviornment is windows, try to solve this in perl, but wondering, in pervious perl which you had provide,
Wait. Let's regroup! This thread specifically asked about 'sed'. I answered that.
> originally, I would like to combine tcl with expect module to get the input, (perl in windows do not have expect), then call perl script to handle to reformat, then called cygwin to process the numbers to re-print the result...don't know if there have any other quick way which not to install too many extra application on windows system.
Your real objective isn't clear. If the core issue is being able to munge text files on a Windows system, Perl is definitely the tool in my opinion. If your objective only needs to be met once, then you might be best servered by copying the source data to a Unix platform; massaging it; and copying ib back to the "other" environment.
As for the un-related (?) question you raised regarding your previous post and the Perl script I provided, any further discussion of that is best raised if you re-open _taht_ thread.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 08:36 AM
тАО09-27-2009 08:36 AM
Re: Need help on TCL scripts
idealy to use,
perl -ne 'print 17 .. 57' show.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 08:47 AM
тАО09-27-2009 08:47 AM
Re: Need help on TCL scripts
If it helps, the 'sed' commands convert to Perl very easily:
# perl -ne 'print if 20..60' file
# perl -ne ''print if /pattern1/../patern2/'
As before (with 'sed') the first line of a file is numbered one.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 01:29 PM
тАО09-27-2009 01:29 PM
Re: Need help on TCL scripts
set fd [open "show.log" "r"]
set lines [split [read $fd] "\n"]
close $fd
set lines [lrange $lines 16 56]
foreach line $lines {puts $line}