Sponsored Content
Top Forums Shell Programming and Scripting check number or character of a file Post 302469889 by onesuri on Monday 8th of November 2010 01:41:55 PM
Old 11-08-2010
Hi,

I have written the script. It is working fine.
On demand, I will receive files in the source directory [Each day I will receive 300 files]. Using control-m scheduler I am scheduling the below shell script every five mins.

But I am facing lot of problems to atomize for the following things also include in the script.

1. Filename passing as a parameter. But I want to atomize to read all the files in the directory execute the shell script one by one.
2. Ex: source files:
All_101010101010.csv
101010_EMP_1200.csv
101011_SALES_3200.csv

First it will check the starting with charter file [Ex: All_101010101010.csv] then it will execute script for only that file. After the completion of the script automatically zip the file and moved to back up directory.

Then execute the script for starting with number files[Ex: 101010_EMP_1200.csv]. After the completion of the script automatically zip the file and moved to back up directory.
And so on....


Code:
#!/bin/sh

####################################################################
# Check the input parameters
####################################################################
if [ $# -ne 1 ]
then
	echo "parameter missing"
	enit 1
fi


Source_file=$1
fname=`echo $Source_file|cut -d '_' -f1`

####################################################################
# Check the source file is a charter or number
####################################################################
case $fname in
	[0-9]*) var=`echo $Source_file|cut -d '_' -f2` ;;
	[a-zA-Z]*) var=`echo $Source_file|cut -d '_' -f1` ;;
	*) echo "Invalid file name" ;;
esac

####################################################################
#Based on the type of file run the data stage job.
####################################################################
if [ $var = 'ALL']
then
	dsjob -server :$SERVER_PORTID 
	      -run 
	      -mode NORMAL 
	      -jobstatus 
	      -param INPUT_GCDB_DIR=$InputFilePath 
	      -param INTERIM_DIR=$SequentialFilePath 
	      -param SCRIPT_DIR=$ShellScriptPath 
	      -param CountryID=$CountryID 
	      -warn 0 $ProjectName $JobName1.$CountryID
elseif [ $var = 'EMP']
then
	dsjob -server :$SERVER_PORTID 
	      -run 
	      -mode NORMAL 
	      -jobstatus 
	      -param INPUT_GCDB_DIR=$InputFilePath 
	      -param INTERIM_DIR=$SequentialFilePath 
	      -param SCRIPT_DIR=$ShellScriptPath 
	      -param CountryID=$CountryID 
	      -warn 0 $ProjectName $JobName2.$CountryID
elseif [ $var = 'SALES']
then
	dsjob -server :$SERVER_PORTID 
	      -run 
	      -mode NORMAL 
	      -jobstatus 
	      -param INPUT_GCDB_DIR=$InputFilePath 
	      -param INTERIM_DIR=$SequentialFilePath 
	      -param SCRIPT_DIR=$ShellScriptPath 
	      -param CountryID=$CountryID 
	      -warn 0 $ProjectName $JobName3.$CountryID
else 
	echo " not valid"
fi

Any help greatly appreciated

Thanks
suri
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

hw can i count the number of character in a file by perl

i want to count the number of character contained in afile using perl cript help me out (1 Reply)
Discussion started by: trupti_rinku
1 Replies

2. Shell Programming and Scripting

how to search string and number in one file and check in the other file

Hi, Can anyone help in the below problem. file1 has the below contents fileset 999 primary-ilist inode 37020 has invalid dotdot (426094) -> Not exist fileset 999 primary-ilist inode 115016 dup block ->... (9 Replies)
Discussion started by: knshree
9 Replies

3. AIX

check for a particular character inside a file and substitute with a given character?

i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character. consider a file test.txt,inside the file... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

4. Shell Programming and Scripting

To check if the first character is a alphabet or number

Hi, I need to find whether the first character in a line is a alphabet or a number. If its a number i should sort it numerically. If its a alphabet i should sort it based on the ASCII value.And if it is something other than alphabet or number then sort it based on ASCII value. The code i used... (2 Replies)
Discussion started by: ragavhere
2 Replies

5. Shell Programming and Scripting

check number of character

hi, I would like to calculate number of character for a number, for exemple : 1200 --> there are 4 characters , 120001 -> 5 characters (4 Replies)
Discussion started by: francis_tom
4 Replies

6. Shell Programming and Scripting

How to check for a character at last line of the file?

this is the csv file. i want to check the last line contains the character N. Record Type#Batch Job ID#Batch Number#FileCreation Date#FileCreation Time#Production/Test Fileindicator#File Character H#0002#0002#20100218#17.25#P#barani Record Type#A#B#C#D#E#F#G#H#J#K#L... (5 Replies)
Discussion started by: barani75
5 Replies

7. Shell Programming and Scripting

How to check newline character in file?

Hi All, I have file with only one record,always be only one record. as like below. if that line contains newline end of the line..no need to add, if not just add the new line character. END OF FILE. ROW COUNT: 7 Please help me.. Thanks, (9 Replies)
Discussion started by: bmk
9 Replies

8. Shell Programming and Scripting

Check Junk character in sql file

Hello, I have two .sql files which I transferred from Windows to Unix (Linux Enterprise Linux Server release 5.3).I want to ensure that these two files have no junk characters in them.How do I do it in the simplest possible way? Many thanks DJ (1 Reply)
Discussion started by: Digjoy83
1 Replies

9. Shell Programming and Scripting

To check for a number inside the file in UNIX

Hi Gurus I am a newbie to Unix programming and I am having a difficulty in finding out a number which is present in a file and storing it in a variable so that i can use it in my shell script. The content of the file "count" is: Count of the files=11 I need to just store the value 11 in... (8 Replies)
Discussion started by: vikramgk9
8 Replies

10. Shell Programming and Scripting

How to check number of group of file.?

Hi Gurus, I need check existing number of file based on the list in file list. for example: in my file list. I have below: abc, file1.txt abc, file2.txt abc, file3.txt abc, file4.txt cde, filea1.txt cde, filea2.txt cde, filea3.txt ... in my current file direcotry, I have file:... (0 Replies)
Discussion started by: ken6503
0 Replies
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.11 30 Jan 2004 script(1)
All times are GMT -4. The time now is 10:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy