Sponsored Content
Operating Systems AIX file_cnt=`ls $in_dir/$file_name | wc -l` not working Post 302709669 by Corona688 on Wednesday 3rd of October 2012 12:18:41 PM
Old 10-03-2012
That method is prone to failures if a directory accumulates too many files, especially on a system like HP-UX where you may be using an old shell. It would be better to use grep -c, though it takes regexes, not globs. A dumb/simple conversion from glob to regex can be done by replacing . with \. and * with .*, prepending ^ and appending $ to force it to match entire lines, but this may not be perfect.

Code:
#!/bin/ksh

while read DIR HOLD GLOB
do
        GLOB="${GLOB/./\\.}" # Replace . with \.
        GLOB="${GLOB/\*/.*}" # Replace * with .*
        GLOB="^${GLOB}\$" # Turn GLOB into ^GLOB$ to match entire line

        if [ ! -e "$DIR" ]
        then
                echo "$DIR does not exist"
        elif [ ! -d "$DIR" ]
        then
                echo "$DIR is not a directory"
                continue
        else
                COUNT="`ls "$DIR" 2>/dev/null | grep -c "$GLOB"`"
                echo "Found $COUNT matching files in directory"
        fi
done < listfile

 

10 More Discussions You Might Find Interesting

1. Solaris

GUI not working... CLI is working fine

Hello, I have X4500 running Solaris 10. I can access it through CLI but I cannot see the GUI. When I reboot it, the GUI works till all the files are loaded (ie., the initial boot sequence) and it prompts me to enter username and password and there it ends. The screen just has a blinking cursor... (4 Replies)
Discussion started by: bharu_sri
4 Replies

2. Linux

FTP not working under Linux but working under any other OS ??? Very strange

Dear all, I am totally despaired and puzzled. Using Filezilla under Windows under the same network as our Linux servers is working. Using FTP command-line client under any of our Linux debian servers is not working ! I tried with different FTP servers -> same problem ! All commands are... (12 Replies)
Discussion started by: magix_ch
12 Replies

3. UNIX for Advanced & Expert Users

Awk expressions working & not working

Hi, Putting across a few awk expressions. Apart from the last, all of them are working. echo a/b/c | awk -F'/b/c$' '{print $1}' a echo a/b/c++ | awk -F'/b/c++' '{print $1}' a echo a/b/c++ | awk -F'/b/c++$' '{print $1}' a/b/c++ Request thoughts on why putting a '$' post double ++... (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

4. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

5. UNIX for Advanced & Expert Users

Advance file_name serech from set of list files in particular directory

Hi All, im hav one requirement, let me explain my requirement. my script will run every one hour and it wil pull files from remote server to my local server.but the d files hwich are pulled my not be in required format wht im expecting in my server. but in my sever in particular dierectory i... (7 Replies)
Discussion started by: Seshendranath
7 Replies

6. Red Hat

Nslookup working but ping not working at windows client

Hi Team we have created a DNS server at RHEL6.2 environment in 10.20.203.x/24 network. Everything is going well on linux client as nslookup, ping by host etc in entire subnet. We are getting problem in windows client as nslookup working as well but not ping. all the firewall is disabled and... (5 Replies)
Discussion started by: boby.kumar
5 Replies

7. Shell Programming and Scripting

File_Name and send email

I have two files file1.txt A.txt file2.txt B.txt Send email to end users as filename as heading and content example: email should be like these file1 A.txt (3 Replies)
Discussion started by: satish1222
3 Replies

8. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

9. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

10. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies
TAP::Parser::SourceHandler::Handle(3pm) 		 Perl Programmers Reference Guide		   TAP::Parser::SourceHandler::Handle(3pm)

NAME
TAP::Parser::SourceHandler::Handle - Stream TAP from an IO::Handle or a GLOB. VERSION
Version 3.26 SYNOPSIS
use TAP::Parser::Source; use TAP::Parser::SourceHandler::Executable; my $source = TAP::Parser::Source->new->raw( *TAP_FILE ); $source->assemble_meta; my $class = 'TAP::Parser::SourceHandler::Handle'; my $vote = $class->can_handle( $source ); my $iter = $class->make_iterator( $source ); DESCRIPTION
This is a raw TAP stored in an IO Handle TAP::Parser::SourceHandler class. It has 2 jobs: 1. Figure out if the TAP::Parser::Source it's given is an IO::Handle or GLOB containing raw TAP output ("can_handle"). 2. Creates an iterator for IO::Handle's & globs ("make_iterator"). Unless you're writing a plugin or subclassing TAP::Parser, you probably won't need to use this module directly. METHODS
Class Methods "can_handle" my $vote = $class->can_handle( $source ); Casts the following votes: 0.9 if $source is an IO::Handle 0.8 if $source is a glob "make_iterator" my $iterator = $class->make_iterator( $source ); Returns a new TAP::Parser::Iterator::Stream for the source. "iterator_class" The class of iterator to use, override if you're sub-classing. Defaults to TAP::Parser::Iterator::Stream. SUBCLASSING
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview. SEE ALSO
TAP::Object, TAP::Parser, TAP::Parser::Iterator, TAP::Parser::Iterator::Stream, TAP::Parser::IteratorFactory, TAP::Parser::SourceHandler, TAP::Parser::SourceHandler::Executable, TAP::Parser::SourceHandler::Perl, TAP::Parser::SourceHandler::File, TAP::Parser::SourceHandler::RawTAP perl v5.18.2 2014-01-06 TAP::Parser::SourceHandler::Handle(3pm)
All times are GMT -4. The time now is 02:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy