Reading files in script from another directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading files in script from another directory
# 1  
Old 04-09-2010
Reading files in script from another directory

Hi

I'm trying to call my files from different directories in my script.

Can you please help me.

Here is my script:

Code:
 
#!/bin/bash
#---------------------------------------------------------------------------------------------------------------------- 
#This script allows the user to input the cellid and new parameter value, the old csv file and what the user 
#would like to name the new csv file. The changed data is then piped to the new file and ready for the import process
#
#./csv_file_change.sh -i -p -o -n
#
#-----------------------------------------------------------------------------------------------------------------------
id="$id"
paramval="$paramval"
oldfile="$oldfile"
newfile="$newfile"
function displayHelp()
{
echo ""
echo " Usage: csv_file_change [ -i -p -o -n ]"
echo ""
echo " -i, --id identified by the cellid "
echo " -p, --paramval identified by the new parameter value "
echo " -o, --oldfile identified by the name of the original file "
echo " -n, --newfile identified by the name of the new altered file "
echo " -h, --help identified by the help menu "
echo ""

}
while getopts " i: p: o: n: h " option
do
case $option in
i ) id="$OPTARG";;
p ) paramval="$OPTARG";;
o ) oldfile="$OPTARG";;
n ) newfile="$OPTARG";;
h ) displayHelp;exit;;
? ) displayHelp;exit;;



esac;
done
 
awk -F, -v id=$id -v paramval=$paramval -v oldfile=$oldfile -v newfile=$newfile '$2==id{$3=paramval}1' OFS="," $oldfile > $newfile

My directory that the file is in is called:

Code:
/C:\cygwin\var\local\dsx\csv

I want to write my resulting files to this directory

Code:
/C:\cygwin\var\local\dsx\output

Can you help me please help me
# 2  
Old 04-09-2010
UNIX filesystems - even cygwin uses a forward slash -
Code:
/cygdrive/C/var/local/dsx/csv

The C drive is usually off the /cygdrive directory - cd / and ls will tell you.

See Cygwin Cheat Sheet - voxforge.org
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading a file from a different directory in a Bash script

Hi all, Given here under a section of a script I am using. SIMDIR="/home/Ins/forces" cd $SIMDIR for file in `ls *.forces` do basename=`echo $file | sed 's/\.*$//'` extname=`echo $file | sed 's/*\(*\)\.\(.*\)/\2\1/'` echo "Processing file: "$basename python convert.py... (4 Replies)
Discussion started by: Theo Score
4 Replies

2. Shell Programming and Scripting

Reading contents of files from a directory

I have a directory with the files, 1st: I want to Diplay each filename, underline it 2nd: Display the contents under the filename and 3rd: Redirect the above content to other file 4th: Remove the files from the directory #!/bin/ksh for i in $( cat $a/b/c.txt ) do echo "... (1 Reply)
Discussion started by: Aditya_001
1 Replies

3. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

4. UNIX for Dummies Questions & Answers

Reading Table name from a list of files in a Directory

Hi , I have searched through the forum but not able to find out any help :( i have a directory having lot of files which contains sql statemtns eg : file 1 contains select from table_name1 where ..................... select from table_name2 where .......... select from ... (3 Replies)
Discussion started by: Trendz
3 Replies

5. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

6. Shell Programming and Scripting

Script which removes files from the first directory if there is a file in the second directory

Script must removes files from the first directory if there is a file with same name in the second directory Script passed to the two directories, it lies with them in one directory: sh script_name dir1 dir2 This is my version, but it does not work :wall: set - $2/* for i do set -... (6 Replies)
Discussion started by: SLAMUL
6 Replies

7. Shell Programming and Scripting

Reading in all files from parent directory (GAWK)

Hi all, I'm very, very new to scripting (let alone SHELL) and was wondering if anyone could help me out as I seem to be in a spot of bother. I collect data (.dat files) which are automatically seperated into several sub directories, so the file paths I'm reading in at the moment would be... (11 Replies)
Discussion started by: gd9629
11 Replies

8. Shell Programming and Scripting

reading files from a directory.

Can some body help me to code this? go to a specific directory.(/home/abcd/test) file1.txt, file2.txt, ... .. filen.txt read the files in side the folder 'test' and print the content of each file into other folder in the same directory lets say(testresult) with the same file name... (4 Replies)
Discussion started by: rocking77
4 Replies

9. AIX

reading files from a directory.

Hi all, I have a shell script where it processes a set of files from a particular directory (shared location among 4 servers). i.e. under this directory /shared/work/ I have a set of files that needs to be processed. Since the number of files are alot, I have this script to be run from 4... (2 Replies)
Discussion started by: haroon_a
2 Replies

10. Shell Programming and Scripting

Reading files in directory

Hi Everyone , have a nice day i need a help on this thing algo is something like in certain path like /root/user1 i have many files , i need a code which could open every file one by one and then each file has contents like this <moid>CcnCounters=CAPv3-Received-Total-Requests, Source =... (3 Replies)
Discussion started by: Dastard
3 Replies
Login or Register to Ask a Question