Check in File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check in File
# 1  
Old 06-05-2012
Check in File

Hello,

In a main shell script, I would be getting the Table name as one of parameter, I need to check whether that table name exist in a Static List, which will have 2 column (Table Name, Column Name) ,
If exist , then I will perform some activities , otherwise exit with no additional process.

For e-g , If the content of the file is
Code:
Table1              Field1
Table2              Field2
Table77            Field77……

In the main script , If Tablename = Table1, then I need to printf the column content from the list , in this case which would be ‘Field1’
I used the following code to check a list of tables in a specific folder, not sure how to check a specific input and check in a file.

Code:
#!/usr/bin/ksh
while read FILE
do
    [ -z "$FILE" ] && continue # ignore blank lines 
    [ -f "$checkfolder/${FILE}" ] && continue
 
        echo "$checkfolder/${FILE} is missing !" >&2     
            err_code=1
done < $path/tmp/$totalFile.lst
        exit $err_code


Please help
Thanks,

---------- Post updated at 02:07 PM ---------- Previous update was at 01:14 PM ----------

I just realised that the table name will appear only one time in the file list, I will better of use grep , something like

`grep $1 /export/home/fusionuk/main.lst | awk -F, '{print $2}'`

Thanks

Last edited by Scrutinizer; 06-05-2012 at 02:21 PM.. Reason: code tags, remove font codes
# 2  
Old 06-05-2012
Quote:
Originally Posted by Shanks
I just realised that the table name will appear only one time in the file list, I will better of use grep , something like

`grep $1 /export/home/fusionuk/main.lst | awk -F, '{print $2}'`
You shouldn't use backticks, because they are deprecated and only supported to be backwards compatible. Use "$(....)" instead.

When you already use awk, you don't need grep, yes?

Code:
$(awk -F, '/'"$1"'/ {print $2}')


I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check Error File attach and email zip file

I need something to say if these two file extensions exist in this directory *err and *rpt zip up these files into one zip file and email them to me. If they don't exist wait 2 hours and check again.... Not sure how to determine if I need to do an if then statement or a while true or a for... (1 Reply)
Discussion started by: xgringo
1 Replies

2. UNIX for Dummies Questions & Answers

After Ftp'ing file to destination how to check the file if it is in correct ASCII and not corrupted

Hi Folks, While transferring file from FTP software like Filezilla the files gets corrupted. Is there any way I can check if the recently transferred file is in ASCII and not corrupted. I have tried using file -i filename command which does tell if the file character set is ASCII or binary... (6 Replies)
Discussion started by: Khan28
6 Replies

3. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

4. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

5. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

6. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

7. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

8. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies

9. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies

10. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question