Function control value in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Function control value in file
# 1  
Old 05-20-2010
Function control value in file

Dear friends,

I need help .. some will say again ; )

I've got a shell script (KSH) with interactive options.

One of the option should match a numeric value but also look inside a file and check if the numeric value match the numeric value chosen.

I've got a function to check if the numeric value is enter is correct from 1 to 7. So the numeric value cannot be 0 or 8 or 10 etc ..

But I am wondering how I could enter a control between the value enter and check if this value exist on the file read ?

How will you do this ?

Thanks for your help.
# 2  
Old 05-20-2010
Hi,
could you paste the code you have? (deleting important information)
# 3  
Old 05-20-2010
Code:
#!/bin/bash
echo -n "enter a number:"
read number
grep -q $number myfile
if [ $? -ne 0  ] then
  echo "number not founf"
fi

grep -q only returns status, does not display anything.
# 4  
Old 05-20-2010
Hello thanks for your quick reply

On first parameter looks like this :

Code:
liste_release[1]="1"
liste_release[2]="2"
liste_release[3]="3"
liste_release[4]="4"

the function that control the value enter looks like this :
Code:
fct_verif_rel ()
{
#
#
i=1
while [ $i -lt 5 ]
do
  if [ $id_release = ${liste_release[$i]} ]
  then
    break
  else
    let i=$i+1
  fi
done
if [ $i -eq 5 ]
  then
  echo "   message \""$id_release"\" not valid"
  echo " "
  fct_usage
fi
}

but I don't know how and where I should enter a control that should read a file and check if the value enter exist and then continue or warning if the numeric value does not exist..

thanks
# 5  
Old 05-20-2010
I think the solution posted by jim mcnamara is good:

Quote:
Originally Posted by Aswex
Hello thanks for your quick reply

On first parameter looks like this :

Code:
liste_release[1]="1"
liste_release[2]="2"
liste_release[3]="3"
liste_release[4]="4"

the function that control the value enter looks like this :
Code:
fct_verif_rel ()
{
#
#

grep -q $id_release YourFile
if [ $? -ne 0 ] 
then
echo "The option is not in the file!" fct_usage??
else
i=1 while [ $i -lt 5 ] do if [ $id_release = ${liste_release[$i]} ] then break else let i=$i+1 fi done if [ $i -eq 5 ] then echo " message \""$id_release"\" not valid" echo " " fct_usage fi
fi }

but I don't know how and where I should enter a control that should read a file and check if the value enter exist and then continue or warning if the numeric value does not exist..

thanks
# 6  
Old 05-20-2010
I will have to try ... I can't do it right now but I think this will not work so easy because the file that should read to check if the value exist looks like this :

1 20100501 20100531
2 20100601 20100630
3 ..etc

I can use awk to exract the first part but I don't know how I could get the first part as value to compare with the value enter. I am not sure to be clear Smilie

Thanks
# 7  
Old 05-20-2010
try then with:

Code:
grep -q "^$id_release " yourfile

so you search for then number at the beginnig of the line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read a control file

Hi I have the below .sh script which receives a argument ftpClient=$1 . This argument i am trying to read from a control file called ftpProperties.control. Based on the argument input(client_ftx OR client_ptm),the script shall read the particular entries from the control file like ftp... (7 Replies)
Discussion started by: samrat dutta
7 Replies

2. Shell Programming and Scripting

Help to Modify File Name in each function before calling another function.

I have a script which does gunzip, zip and untar. Input to the script is file name and file directory (where file is located) I am reading the input parameters as follows: FILENAME=$1 FILEDIR=$2 I have created 3 functions that are as follows: 1) gunzip file 2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies

3. Shell Programming and Scripting

Check whether file is processed in a control file list

I've a list of files which got processed in Target table A and stored in a control file(list of control files). I've want to trigger another process (later) based on this list of files and load into Target table B and continue running this process until this file list is exhuasted. How do I come... (1 Reply)
Discussion started by: manojg9
1 Replies

4. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

5. UNIX for Dummies Questions & Answers

Control and monitoring file

Hi guys today i have new situation to resolve. I need to create a script that the first part it's already done but the problem appear when i run other sart_script inside of it. i need to check a log file until it stop after run the star script when the log file stop write, then make a copy file... (2 Replies)
Discussion started by: Newer
2 Replies

6. Shell Programming and Scripting

Control and monitoring file

Hi guys today i have new situation to resolve. I need to create a script that the first part it's already done but the problem appear when i run other sart_script inside of it. i need to check a log file until it stop after run the star script when the log file stop write, then make a copy file... (1 Reply)
Discussion started by: Newer
1 Replies

7. Shell Programming and Scripting

Control content of file

I want to control content of my mounted flash card which have string like "kernel32.dll". I explore some virus files have content of "kernel32". I find those files and rename this files.By shell programming. Not files name kernel32.dll. File include string like "kernel32.dll". Help me please (2 Replies)
Discussion started by: cashua66
2 Replies

8. Shell Programming and Scripting

Control file

if TERM has the value vt220, where will you expect to find its control file (0 Replies)
Discussion started by: thelakbe
0 Replies

9. Shell Programming and Scripting

Checking for a control file before processing a data file

Hi All, I am very new to Shell scripting... I got a requirement. I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data... (4 Replies)
Discussion started by: purna.cherukuri
4 Replies

10. SuSE

Disabling interrupt function of Control-C key combination

I am using informix RDBMS over SUSE LINUX. In linux if you press control-c it acts as an interrupt key. In my program I have used control-c to perform certain functions but it is being overriden by interrupt function of control-c key combination of SUSE LINUX. Kindly suggest me a solution by which... (1 Reply)
Discussion started by: V.V.KUMAR
1 Replies
Login or Register to Ask a Question