Sponsored Content
Full Discussion: Shell to PERL
Top Forums Shell Programming and Scripting Shell to PERL Post 302606029 by Ygor on Friday 9th of March 2012 11:16:55 AM
Old 03-09-2012
Just for fun, I thought I'd test it out...
Code:
$ cat sh.1
if [[ ! -f errors.txt ]]
then # 1st time
   grep -c $RANDOM~~$RANDOM *.log > errors.txt
fi
mv errors.txt errors.old
grep -c ERROR *.log > errors.txt
comm -13 errors.old errors.txt | while read ERR
do
   LOG=$(echo $ERR|cut -d: -f1)
   CNT=$(echo $ERR|cut -d: -f2)
   if [[ $CNT -gt 0 ]]
   then
       echo do something with file: $LOG which has error count: $CNT
   fi
done

$ echo ERROR > A.log

$ echo okay > B.log

$ sh sh.1
do something with file: A.log which has error count: 1

$ sh sh.1

$ echo ERROR >> B.log

$ echo ERROR > C.log

$ sh sh.1
do something with file: B.log which has error count: 1
do something with file: C.log which has error count: 1

$ echo ERROR >> A.log

$ echo ERROR >> B.log

$ sh sh.1
do something with file: A.log which has error count: 2
do something with file: B.log which has error count: 2

$ echo ERROR >> B.log

$ echo ERROR >> C.log

$ sh sh.1
do something with file: B.log which has error count: 3
do something with file: C.log which has error count: 2

$ rm errors.txt #--reset

$ sh sh.1
do something with file: A.log which has error count: 2
do something with file: B.log which has error count: 3
do something with file: C.log which has error count: 2

$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies

2. UNIX for Dummies Questions & Answers

shell to perl

hi all, Can we change a shell script into a perl script instead of writing a fresh one in perl? Is there any utility present that can be used for this purpose? please help me. Thanks in advance.. (1 Reply)
Discussion started by: arthi
1 Replies

3. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

4. Shell Programming and Scripting

Perl Vs Shell Programming

Can someone please tell me what the big deal about perl is? i have been doing shell programming for quite a number of years and I have to say, there's very little if any thing that I can't do in shell programming. i just need to investigate how to do it. so, my question is, does deep... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

Shell to perl

Hi all experts, I am new to Perl. Could you please help me to convert the following SHELL script to PERL ? I will appreciate. #!/bin/bash #set -x fileday=$1 result_file=Total`date +%Y%m%d%H%M` out_folder=/home/cmd/pm_analyze tmp_folder=/tmp/pmtmp datatype='split licenceCounter... (4 Replies)
Discussion started by: jinanchen
4 Replies

6. UNIX for Dummies Questions & Answers

perl through shell

Can we call a perl script/ commands through a shell script? (1 Reply)
Discussion started by: chn10db001
1 Replies

7. Shell Programming and Scripting

Shell or Perl?

Hello, I am looking for some basic script help, I am currently tailing a log with a simple tail –f, combined with egrep –vi to remove some messages from the tail, i do not want to see. . I wanted to create something a little more complex were if it’s possible to script this into... (4 Replies)
Discussion started by: hamon
4 Replies

8. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

9. Shell Programming and Scripting

Shell / Perl help

Hi, here is my problem. I have a command line tool to process files. Now I have few hundreds of files to process. So I have written a perl script to generate the command dynamically using variables for the arguments. when I use backtick to execute those it creates error. the shell doesn't get the... (4 Replies)
Discussion started by: jith
4 Replies

10. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies
SCRIPT(1)						    BSD General Commands Manual 						 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-a] [-c COMMAND] [-e] [-f] [-q] [-t] [file] DESCRIPTION
Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Options: -a Append the output to file or typescript, retaining the prior contents. -c COMMAND Run the COMMAND rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -e Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n. -f Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can super- vise real-time what is being done using `cat foo'. -q Be quiet. -t Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1). HISTORY
The script command appeared in 3.0BSD. BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. AVAILABILITY
The script command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. Linux July 30, 2000 Linux
All times are GMT -4. The time now is 12:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy