| | |
perform file actions located in another direcory
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 9
Reputation:
Solved Threads: 0
hai dani,
i have a problem with listing the contents of file in another directory.
my default path is in /home/pallu
where my file called DirProg script exists , now i want to find any file which starts with a or A in a dir and store the content in another file called output.dat.
im not able to dispaly file in the directory threw script.
my code is below:----
echo "Enter a directory name"
read dname
if test -d $dname
then
if grep -c ^A dirlist1
then
fname=`grep ^A dirlist1`
cat $fname|cat > output.dat
echo "Content of file is written in a file called output.dat"
fi
else
echo "The entered name is not a directory"
fi
thanks in advance.
i have a problem with listing the contents of file in another directory.
my default path is in /home/pallu
where my file called DirProg script exists , now i want to find any file which starts with a or A in a dir and store the content in another file called output.dat.
im not able to dispaly file in the directory threw script.
my code is below:----
echo "Enter a directory name"
read dname
if test -d $dname
then
if grep -c ^A dirlist1
then
fname=`grep ^A dirlist1`
cat $fname|cat > output.dat
echo "Content of file is written in a file called output.dat"
fi
else
echo "The entered name is not a directory"
fi
thanks in advance.
0
#2 Oct 11th, 2009
You should probably use
find : Shell Scripting Syntax (Toggle Plain Text)
#!/bin/bash echo -n "Enter a directory: " read dir if ! test -d ${dir}; then echo "Directory does not exist" exit fi # To search child directories rm -f output_withchildren.dat find ${dir} -type f -iname a\* >> output_withchildren.dat # To not search child directories rm -f output_nochildren.dat find ${dir} -maxdepth 1 -type f -iname a\* >> output_nochildren.dat
Last edited by sknake; Oct 11th, 2009 at 8:02 am.
•
•
Join Date: Dec 2008
Posts: 64
Reputation:
Solved Threads: 13
0
#3 Oct 19th, 2009
•
•
•
•
hai dani,
i have a problem with listing the contents of file in another directory.
my default path is in /home/pallu
where my file called DirProg script exists , now i want to find any file which starts with a or A in a dir and store the content in another file called output.dat.
im not able to dispaly file in the directory threw script.
my code is below:----
Please use CODE tags.
•
•
•
•
Shell Scripting Syntax (Toggle Plain Text)
echo "Enter a directory name" read dname if test -d $dname then if grep -c ^A dirlist1 then fname=`grep ^A dirlist1` cat $fname|cat > output.dat
Why two cats?
Shell Scripting Syntax (Toggle Plain Text)
cat $fname > output.dat
•
•
•
•
Shell Scripting Syntax (Toggle Plain Text)
echo "Content of file is written in a file called output.dat" fi else echo "The entered name is not a directory" fi
Shell Scripting Syntax (Toggle Plain Text)
read dname if [ -d "$dname" ] then printf "%s\n" "$dname"/A* > output.dat else echo "The entered name is not a directory" fi
Chris F.A. Johnson
http://cfajohnson.com
http://cfajohnson.com
![]() |
Similar Threads
- Help searching for a keyword in a file..... (C)
- open file in same folder as application (C#)
- Search function Not working. (Windows NT / 2000 / XP)
- xml web configuration file (C#)
- Antivermon malware? HJT log included. (Viruses, Spyware and other Nasties)
- Including header file using HTML (HTML and CSS)
- Included file not found during compile time. (C++)
- locating a file... (C++)
- How do I pass data from a recordset on asp page towards an array on js file (HTML and CSS)
- Saving a file using C++ (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: how to recursive search of subdiretories in BASH script
- Next Thread: Need Filesystem Maintenance Script
| Thread Tools | Search this Thread |






