How to Check whether list file present in TXT file exist or not


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Check whether list file present in TXT file exist or not
# 1  
Old 05-28-2009
How to Check whether list file present in TXT file exist or not

Hi All,

I have txt file which has list of files. I have to check whether these files exist or not.

Thanks
supriya
# 2  
Old 05-28-2009
Read the txt file and traverse through the file using for loop and attach this condition for existence of the file.

Code:
if [ -r filename ]; then

# 3  
Old 05-28-2009
Can you please provide me the full code plz for reading and traversing also as i am failing over there

Thanks
Supriya
# 4  
Old 05-28-2009
Please try it out yourself its not so difficult.

And if still not successful I give it
# 5  
Old 05-28-2009
for i in $1
do
if [ ! -f $i ]; then
let countValue=1
fi
done
This is the code i am using and it is not working. where $1 is my txt file name

Thanks
Supriya
# 6  
Old 05-28-2009
sample code

Code:
TESTBOX>

ip=$1
for i in `cat "$ip"`
do
if [ -r $i ]; then
echo "file $i exists"
else
echo "file $i doe n't exists"
fi
done

# 7  
Old 05-28-2009
Thanks. It worked
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if file is present using input from another file

Hello, I have a comma delimited file such as: cat /statistics/support/input.txt ID,Serial,quantitity,atribute1,atribute2 1,89569698,5,800,9900, 1,35568658,8,1200,5550 1,89569698,8,320,5500 1,68753584,85,450,200 ID should always have 1 digit, Serial 8 digits, and the others may... (2 Replies)
Discussion started by: alex2005
2 Replies

2. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

3. Shell Programming and Scripting

Check if file exist

Hi, I created following script to check if file exist: #!/bin/bash SrcDir=$1 SrcFileName=$2 SrcTimePeriod=$3 if ;then echo 1 else echo 0 fi I ran it like: /apps/Scripts/FileExist.sh /apps/Inbox file1 2nd_period_2010 Even file exist at that location, my above command is... (4 Replies)
Discussion started by: palak08
4 Replies

4. Shell Programming and Scripting

Check if file exist

Hi, I am trying to create a bash script which will check if file exist then remove that file else do nothing. I have to do same process for three files in same script. I have written code for one file and trying to run it. if then rm -r /user1/abc/File1 fi When I run this code it... (1 Reply)
Discussion started by: palak08
1 Replies

5. Shell Programming and Scripting

Help needed in extracting text present between two headers in .txt file

Hi All, Please help me out in fllowing problem. I have text file which contains the data in following format. Contents of file.txt are setregid02 Test that setregid() fails and sets the proper errno values when a non-root user attemps to change the real or effective... (2 Replies)
Discussion started by: varshit
2 Replies

6. Shell Programming and Scripting

Check if file exist

Hi Does anybody know how I can check if a file exists i.e. see bellow, this doesn't work by the way and if tried countless variations on this file1=$one/file111.txt if then echo "Present" else echo "Not present" fi result : Not present (file is already present, eventhough its... (3 Replies)
Discussion started by: gksenthilkumar
3 Replies

7. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

8. 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

9. UNIX for Dummies Questions & Answers

how to check if the file exist or not?

say i would like to check if the file is existed before i use rm command. How can i do it? i know if i can use find, but i would like to have a good interface (in a shell script) thks (3 Replies)
Discussion started by: gusla
3 Replies
Login or Register to Ask a Question