Sponsored Content
Full Discussion: Pattern Matching
Top Forums Shell Programming and Scripting Pattern Matching Post 302482630 by R0H0N on Wednesday 22nd of December 2010 06:19:35 AM
Old 12-22-2010
Code:
cd destFold                     # reach to destination folder
ls sh*.* | sed 's/\..*//g' | sort -u | while read line                  # list files which are in sh*.* format | remove everything after . with sed(i.e. sh123.12 will become sh123) | sort them uniquely | one by one read filenames(i.e. sh123, sh1234, sh12, etc..) 
do
    cnt=`ls ${line}.* | wc -l`                # take count of files in destFold directory
    if [ $cnt -ge 15 ] ; then                   # if count is greater then 15
        pid=`echo "$line" | sed -n 's/sh//g'`                   # extract pid from line by removing sh(i.e. sh123 will be 123, sh1234 will be 1234)
        kill -9 $pid                               # kill that pid as requested
    else
         echo ""                              # else do nothing
    fi
done

This is only for 1 time. If u want this to be monitored then run while loop again in loop.

Last edited by R0H0N; 12-22-2010 at 07:34 AM..
R0H0N
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies

2. UNIX for Dummies Questions & Answers

Pattern Matching

Hi Folks, I have the following requirement: I have a file that is containing numerous queries. The tables name mentioned in the queries are in the following format : SchemaName.Tablename. e.g COPDB.TableName. I need to take out all the COPDB.TableName pattern and write it to a different... (0 Replies)
Discussion started by: Siv_Pat
0 Replies

3. Shell Programming and Scripting

Pattern Matching

Hi Folks, I have the following requirement: I have a file that is containing numerous queries. The tables name mentioned in the queries are in the following format : SchemaName.Tablename. e.g COPDB.TableName. I need to take out all the COPDB.TableName pattern and write it to a different... (6 Replies)
Discussion started by: Siv_Pat
6 Replies

4. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

5. Shell Programming and Scripting

sed - matching pattern one but not pattern two

All, I have the following file: -------------------------------------- # # /etc/pam.d/common-password - password-related modules common to all services # # This file is included from other service-specific PAM config files, # and should contain a list of modules that define the services... (2 Replies)
Discussion started by: RobertBerrie
2 Replies

6. UNIX for Dummies Questions & Answers

Find pattern suffix matching pattern

Hi, I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. ... (5 Replies)
Discussion started by: rajeshwebspere
5 Replies

7. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

8. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

9. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

10. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies
cmx(8)							      System Manager's Manual							    cmx(8)

Name
       cmx - generic communication exerciser

Syntax
       /usr/field/cmx [ -h ] [ -ofile ] [ -tn ] -l line-1 ...

Description
       The  exerciser will write, read, and validate random data and packet lengths on a given communications line.  The line under test must have
       a loopback connector attached to the distribution panel or the cable and the line must be disabled in the file and a non-modem line.   That
       is, the flag must be set to off.

       The exerciser runs until or kill -15 pid is sent to the process.

       A  logfile  is  made  in for you to examine and then remove.  If there are errors listed in the logfile, make sure that you check the file,
       because that is where the driver and kernel error messages are saved.

       You must specify the -l flag followed by the lines to test.  The line-n arguments identify the lines to be tested.  A maximum of  32  lines
       can  be	tested	at  any  one time.  The line-n arguments are specified as names taken from the directory without the letters ``tty''.  For
       example, if the directory lists tty03, the line argument is 03.

       The DEVICES section lists the devices that can be tested.

Restrictions
       If there is a need to run a system exerciser over an NFS link or on a diskless system there are some  restrictions.   For  exercisers  that
       need  to  write into a file system, such as the target file system must be writable by root.  Also the directory, in which any of the exer-
       cisers are executed, must be writable by root because temporary files are written into the current directory.   These  latter  restrictions
       are sometimes difficult to overcome because often NFS file systems are mounted in a way that prevents root from writing into them.  Some of
       the restrictions may be overcome by copying the exerciser to another directory and then executing it.

Options
       -h     Prints help message about this command.

       -ofile Save output diagnostics in file.

       -tn    Run time in minutes (n).	The default is to run until a or kill -15 pid is sent to the process.

Restrictions
       Pseudo devices (those whose first character after tty is p, q, r, s, t, u) cannot be tested.  Neither can lta devices with major #39.

Devices
       Use the command on to find out which tty line corresponds to a device line number.

Examples
       The following example runs the exerciser for 60 minutes on lines 00, 13, 22, and 32.
       % /usr/field/cmx -t60 -l 00 13 22 32
       The following example runs the exerciser on lines 11, 42, 45, and 76 in the background until interrupted by a or kill -15 pid.
       % /usr/field/cmx -l 11 42 45 76 &

See Also
       Guide to System Exercisers

																	    cmx(8)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy