Unable to write to a file within a loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unable to write to a file within a loop
# 1  
Old 11-15-2010
Unable to write to a file within a loop

Hi All,

Following is the program that i have written in cygwin. The redirection of the unfound $param1 to error.txt file doesnt work.Can any one help?

Code:
 
#!/usr/bin/sh
fname=$1
sed 's/ //g' "$fname" > fname1
while read i
do
    echo $i > file1
    #param1 is script name
    param1=`awk -F , '{print $1}' file1`
    param1="$param1.sql"
    #param2 is BL
    param2=`awk -F , '{print $2}' file1`
    #param3 is folder name
    param3=`awk -F , '{print $3}' file1`
    #create config spec file
    echo "element * $param2" > cs.txt
    echo "element * /main/LATEST" >> cs.txt
    #cat cs.txt
    #create directory structure
    mkdir -p "$param3"
    #Map UCM drive
    cd /cygdrive/m/ht62_ucm/GIS_COMP
    cleartool setcs -tag ht62_ucm d:/prj/cs.txt
    echo set config spec status is $?
    fscript1=`cleartool find ./$param3 -element "lbtype_sub($param2)" -name $param1 -print`
    if [ "$fscript1" = "" ]
    then
	echo script $param1 not found >> error.txt
    else
	echo script $param1 is found
	fscript2=`echo "$fscript1" | sed 's/@@//g'`
	echo copying file...
	cp $fscript2 "/cygdrive/d/prj/$param3" 2>/dev/null
    fi
    cd /cygdrive/d/prj
done < fname1
echo Copy complete


Last edited by pludi; 11-15-2010 at 05:59 AM.. Reason: fixed indentation
# 2  
Old 11-15-2010
Put a "set -x" before fname=$1 and when you execute the script,
it will show you the result of each command.

Code:
#!/usr/bin/sh

set -x

fname=$1
echo $fname

Code:
./blah.sh myfile.dat
+ fname=myfile.dat
+ echo myfile.dat
myfile.dat

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Unable to write to NFS mounted directory

Hi, I have exported a few nfs mounts from one server to the nfs clients. This is my nfs server dfstab : # cat /etc/dfs/dfstab # place share(1M) commands here for automatic execution # on entering init state 3. # # share <pathname> # .e.g, # share -F... (3 Replies)
Discussion started by: anaigini45
3 Replies

2. Shell Programming and Scripting

Unable to compare to a previous value of a variable in a while loop for a file

Hello All, I'm working on a script that will actually read a file consisting of data like the below:(ReportID,Sub_reportID,Sub_reportName) 1,1,ABC 1,2,DEF 1,3,GHI 2,1,JKL 2,2,MNO 3,1,PQR I want to read the Sub Report details for a Report_ID using while loop and write these values into... (6 Replies)
Discussion started by: venkat_reddy
6 Replies

3. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

4. UNIX for Dummies Questions & Answers

Unable to write to a mounted NFS share

Hi All, I created a nfs share in the server(Solaris 10) with the following command and also updated the dfstab file share -F nfs -o rw=server_name2,anon=0 /to_share And then in the client(solaris 10) added the following command to mount the share mount -F nfs server_name1:/to_share... (4 Replies)
Discussion started by: Rossdba
4 Replies

5. Red Hat

Unable to write files on a filesystem

hi mounted filesystem is 50% and appropriate permissions were there but im still unable to write files ? (3 Replies)
Discussion started by: rajeshz
3 Replies

6. Programming

unable to send read and write serial port

hey frns pls help me out !! i hav a code of c that i have to include in my project. i am using a device (geomeda) that has unix based OS. it also support SIM card for connecting to server . I need to send SMS to user from this device.. below code is not working .. i am unable to send sms and the... (7 Replies)
Discussion started by: yashwantkumar
7 Replies

7. Shell Programming and Scripting

Push records to array during implicit loop and write to file

NEWBIE ALERT! Hi, I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies

8. Shell Programming and Scripting

help needed .. Unable to write the data to new file after matching the pattern

Hi, i am pretty new to Unix environment ..... Can i get some help from any of you guyz on writing Unix script. my requirement is like reading a csv file, finding a specific pattern in the lines and repalce the string with new string and write it to another file. My file is file ABC123.dat... (3 Replies)
Discussion started by: prashant_jsw
3 Replies

9. Shell Programming and Scripting

trying to write a script to loop through a port info file

Below is part of a script i have written to loop through part of a port info file. How do i continue the script to get info for OS Device Name, manufacturer and then put information into an array? HBA Port WWN: 10000000c9420b4b OS Device Name: /dev/cfg/c10 Manufacturer: Emulex... (5 Replies)
Discussion started by: rcon1
5 Replies

10. Shell Programming and Scripting

Loop through file and write out lines to file(s)

Hi, I am new to ksh scripting so your help will be much appreciated. I have a file called file.txt which looks like this Header 20050702 20050703 ABC DEF Header 20050703 20050704 123 456 Header 20050704 20050705 XXX YYY What I am trying to do is write out each of the record... (7 Replies)
Discussion started by: Jtrinh
7 Replies
Login or Register to Ask a Question