I am wondering if there is any way to search for files in the c-shell
without having to write a perl script?
Thanks,
-Eric
Thanks,
-Eric
seach for files? you might be able to use 'foreach' but it's hard to sayQuote:>I am wondering if there is any way to search for files in the c-shell
>without having to write a perl script?
In comp.unix.shell,
:I am wondering if there is any way to search for files in the c-shell
:without having to write a perl script?
One writes nothing in the csh. Period.
One can, however, call find:
find . -name '*.[ch]' -print | xargs egrep pattern /dev/null
--tom
--
"If Christianity were to disappear, in time, even the
churches would suffer." --Jonathan Swift
In comp.unix.shell,
euman...@mail2.sas.upenn.edu (Eric M. Umansky) writes:
:I am wondering if there is any way to search for files in the c-shell
:without having to write a perl script?
Or just call an already-written perl program.
--tom
#!/usr/bin/perl
#
# tcgrep: tom christiansen's rewrite of grep
# tchr...@colorado.edu
# see usage for features
# yet to implement: -f
# v1.0: Thu Sep 30 16:24:43 MDT 1993
# v1.1: Fri Oct 1 08:33:43 MDT 1993
$| = 1;
&parse_args;
&init;
&matchfile(@ARGV);
exit(2) if $Errors;
exit(0) if $Grand_Total;
exit(1);
######################################
sub init {
($me = $0) =~ s!.*/!!;
$Errors = $Grand_Total = 0;
$| = 1;
%Compress = (
'z', gzcat,
'gz', gzcat,
'Z', zcat,
);
FILE: while ($file = shift(@_)) {
if (-d $file) {
if (-l $file && @ARGV != 1) {
warn "$me: \"$file\" is a symlink to a directory\n"
if $opt_T;
next FILE;
}
if (!$opt_r) {
warn "$me: \"$file\" is a directory, but no -r given\n"
if $opt_T;
next FILE;
}
if (!opendir(DIR, $file)) {
unless ($opt_q) {
warn "$me: can't opendir $file: $!\n";
$Errors++;
}
next FILE;
}
@list = ();
for (readdir(DIR)) {
push(@list, "$file/$_") unless /^\.{1,2}$/;
}
closedir(DIR);
if ($opt_t) {
local(@dates, $i);
for (@list) { push(@dates, -M) }
@list = @list[sort { $dates[$a] <=> $dates[$b] } 0..$#dates];
} else {
@list = sort @list;
}
&matchfile(@list);
next FILE;
}
if ($file eq '-') {
warn "$me: reading from stdin\n" if -t STDIN && !$opt_q;
$name = '<STDIN>';
} else {
$name = $file;
unless (-f $file || $opt_a) {
warn qq($me: skipping non-plain file "$file"\n) if $opt_T;
next FILE;
}
($ext) = $file =~ /\.([^.]+)$/;
if ( $Compress{$ext} ) {
$file = "$Compress{$ext} <$file |";
} elsif (! (-T $file || $opt_a)) {
warn qq($me: skipping binary file "$file"\n) if $opt_T;
next FILE;
}
}
warn "$me: checking $file\n" if $opt_T;
if (!open(FILE, $file)) {
unless ($opt_q) {
warn "$me: $file: $!\n";
$Errors++;
}
next FILE;
}
$total = 0;
$matches = 0;
LINE: while (<FILE>) {
$matches = 0;
if ($opt_H) { $matches = s/$Pattern/${SO}$&${SE}/go }
elsif ($opt_v) { $matches = !/$Pattern/o }
elsif ($opt_C) { $matches++ while /$Pattern/go }
else { $matches++ if /$Pattern/o }
next LINE unless $matches;
$total += $matches;
if ($opt_p || $opt_P) {
local($*);
s/\n{2,}$/\n/ if $opt_p;
s,$/$,,o if $opt_P;
}
print("$name\n"), next FILE if $opt_l;
$opt_s || print $mult && "$name:",
$opt_n && "$.:",
$_,
($opt_p||$opt_P) && ('-' x 20)."\n";
next FILE if $opt_1;
}
} continue {
print $mult && "$name:", $total, "\n" if $opt_c;
}
$Grand_Total += $total;
Standard grep options:
i case insensitive
n number lines
c give count of lines matching
C ditto, but >1 match per line possible
w word boundaries only
s silent mode
x exact matches only
v invert search sense (lines that DON'T match)
h hide filenames
e expression (for exprs beginning with -)
f file with expressions [unimplemented]
l list filenames matching
Specials:
1 1 match per file
H highlight matches
u underline matches
r recursive on directories or dot if none
t process directories in `ls -t` order
p paragraph mode (default: line mode)
P ditto, but specify separator, e.g. -P '%%\\n'
a all files, not just plain text files
q quiet about failed file and dir opens
T trace files as opened
EOF
require 'getopts.pl';
if ($_ = $ENV{TCGREP}) {
s/^[^\-]/-$&/;
unshift(@ARGV, $_);
}
&Getopts("inqcClsue:f:xwhva1pHtrT-P:") || &usage;
die "-f unsupported" if $opt_f;
$Pattern = $opt_e || shift(@ARGV) || &usage;
eval { /$Pattern/, 1 } || die "$me: bad pattern: $@";
if ($opt_H || $opt_u) {
$ospeed = 13; # bogus but shouldn't hurt; means 9600
require 'termcap.pl';
&Tgetent($ENV{TERM} || 'vt100');
($SO, $SE) = $opt_H ? @TC{'so','se'} : @TC{'us','ue'};
}
if ($opt_i) {
if ($] < 5) {
$Pattern =~ s/\w/[\u$&\l$&]/gi;
} else {
$Pattern = "(?i)$Pattern";
}
};
$opt_p && ($/ = '', $* = 1);
$opt_P && ($/ = eval(qq("$opt_P")), $*=1); # for -P '%%\n'
$opt_w && ($Pattern = '\b' . $Pattern . '\b');
$opt_x && ($Pattern = "^$Pattern\$");
$mult = 1 if ($opt_r || (@ARGV > 1) || -d $ARGV[0]) && !$opt_h;
$opt_1 += $opt_l;
$opt_H += $opt_u;
$opt_c += $opt_C;
$opt_s += $opt_c;
$opt_1 += $opt_s && !$opt_c;
@ARGV = ($opt_r ? '.' : '-') unless @ARGV;
$opt_r = 1 if !$opt_r && grep(-d, @ARGV) == @ARGV;
> It isn't a C-shell function. Use "find". i.e.
> find /dir -name file.txt -print
> if you need further assistance "man find"
> --
> Applied Intelligence Group Phone: (405) 341-7700
> 501 East 15th Street, Suite 202 Fax: (405) 341-8898
> Edmond, OK 73013
find /dir -name file.txt -print > myfile
Luis
You could try using the Z shell--
echo **/file.txt # search entire directory structure south of `pwd` for file.txt
--Dave
--
http://armf18.dow.on.doe.ca:6700/~dbrown/ Dave Brown, goo, rogue news admin
"Please stop posting the same post in the linked effect all over the internet."
--some AOL user on crossposting
1. In search of Solaris 2.5 Netscape Navigator 3.0 plug ins
I am searching for plugins for Netscape Navigator on a SPARC Solaris 2.5
system. While any help would be appreciated, I am especially looking for
plugs for RealAudio, wav, and Shockwave files.
Surely I don't have to go out and buy an IBM PC running windows or a
just to be able to access sites which use these technologies.
--
:s <URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
:s Unless explicitly stated to the contrary, nothing in this posting should
:s be construed as representing my employer's opinions.
2. Disgusted with kbuild developers
5. how to call csh scripts from inside other csh scripts
7. ksh to csh and/or csh to ksh
8. Get the most from your "Experience" 61337029
9. csh -> ksh or ksh -> csh EQUIVALENTS NEEDED....
11. csh commands within csh scripts
12. Where do I get csh source code? CSH
13. csh: if-then-else-endif in csh alias?