Visit Our UNIX and Linux User Community


How to write shell script for input file name format checking?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to write shell script for input file name format checking?
# 1  
Old 09-23-2010
Power How to write shell script for input file name format checking?

Hello,

I had written a shell script that accepts input file as cmd line argument and process this file.
Code:
if [ $# -eq 1 ]; then
if [ -f $1 ]; then  
 . $1   
  LOGFILE="$LOG_FILE/MIG_BIOS.log"; 
  get_input_file
else   
 ERROR_CODE=MSCRM0005_003  
 error "$ERROR_CODE : Input file $1 is not available";  
 exit 1
fi
else
 echo "usage : $usage";
fi

I want a help in writting a get_input_file function which checks for file name format.
My input file name format is MIG_CR_<TYPE>_<TIMESTAMP>.<EXT>
Code:
get_input_file(){
FILE = '$1'
#checking file exist or not
if [ ! -f $FILE ]; then   
 echo "$FILE : does not exists"  
 exit 1
elif [ ! -r $FILE ]; then   
 echo "$FILE: can not read"   
 exit 2
fi
// check file name format is correct or not
}

Can anyone tell me how can I check the format of file name?
Please help me out. Thanks in advance. Image

Last edited by Franklin52; 09-23-2010 at 08:32 AM.. Reason: adding code tags
# 2  
Old 09-23-2010
Hi,

Your post is completely unreadable, please edit the post and use indentation and code tags.

Regards
# 3  
Old 09-23-2010
In the format MIG_CR_<TYPE>_<TIMESTAMP>.<EXT>
What do <TYPE> <TIMESTAMP> and <EXT> look like?
in other words, what are the authorized values of those substrings?
# 4  
Old 09-24-2010
Hi,

Thanks for reply.
Here are values,
Code:
TYPE = GLOBAL/PARTIAL
TIMESTAMP = yyyymmddhhmmss (20100903040506)
EXT = CSV / zip / gz


Last edited by Scott; 09-24-2010 at 09:23 AM.. Reason: Code tags

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies

2. Shell Programming and Scripting

Need help to write a shell script to convert text file to excel file.

Hi Everyone, I want your help to write a script which will take text file as input and on the basis of delimiter ":"script will create excel sheet. Example input: IpAdress:InstanceName:Port:ServerName 10.255.255.1:abc:2232:xyz_abc Output should be an excel sheet like below: Column... (8 Replies)
Discussion started by: akabhinav18
8 Replies

3. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

4. Shell Programming and Scripting

Write a shell program with input

Hi, Here is my question: I want a shell script which I name as 'del', and can be used as del(string). when run del(string), it will delete several directories at different locations in my system,like: rm -fr /lustre/fs/scratch/user/$string rm -fr /home/user/$string rm -fr... (4 Replies)
Discussion started by: 1988PF
4 Replies

5. Shell Programming and Scripting

how to write multiple lines to a file using shell script?

I need to create an xml using shell script, but i first want to know how can i write multiple lines to file using shell script? (7 Replies)
Discussion started by: vel4ever
7 Replies

6. Shell Programming and Scripting

checking users input to file

ok im sorta stuck on this, The user enters a car model and it has to check it in a text file in the current directory. If the car model is not in the file, user has to enter another model This is what i have so far read -p "Enter a car model: " car1 grep -w $car1=$(cat carMakes.txt)... (3 Replies)
Discussion started by: gangsta
3 Replies

7. Shell Programming and Scripting

write shell script to rename file

hi, I need some help in writing shell script in a bourne shell.I am trying to rename the file.. eg. find /root/data -type f -name "text*) | while read FILES do newfile=${FILES/type_2.0_20101208_34.xml / tmp.xml} mv "$FILES" "$newfile" done above written script is working...If the... (7 Replies)
Discussion started by: shubhig15
7 Replies

8. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

9. Shell Programming and Scripting

Write a new file from 2 files as input to the script

Hi- I am hoping someone can give me some pointers to get me started. I have a file which contains some dn's .e.g file 1 cn=bob,cn=user,dc=com cn=kev,cn=user,dc=com cn=john,cn=user,dc=com I have a second file e.g. file.template which looks something like :- dn: <dn> objectclass:... (5 Replies)
Discussion started by: sniper57
5 Replies

10. Shell Programming and Scripting

Regarding checking the file format

Hi, This with reference to my earlier thread. I have file called input that has 2 values. Now I have to check whether the 2 fileds are seperated by a "|" or not. I am not able to do this with the following script. while read line do first=`echo $line | cut -f1 -d'|'` ... (8 Replies)
Discussion started by: sendhilmani123
8 Replies

Featured Tech Videos