Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Unable to write to a file within a loop Post 302471769 by janardhanamk on Monday 15th of November 2010 04:44:08 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Config::YAML(3pm)					User Contributed Perl Documentation					 Config::YAML(3pm)

NAME
Config::YAML - Simple configuration automation VERSION
Version 1.42 SYNOPSIS
Config::YAML is a somewhat object-oriented wrapper around the YAML module which makes reading and writing configuration files simple. Handling multiple config files (e.g. system and per-user configuration, or a gallery app with per-directory configuration) is a snap. use Config::YAML; # create Config::YAML object with any desired initial options # parameters; load system config; set alternate output file my $c = Config::YAML->new( config => "/usr/share/foo/globalconf", output => "~/.foorc", param1 => value1, param2 => value2, ... paramN => valueN, ); # integrate user's own config $c->read("~/.foorc"); # integrate command line args using Getopt::Long $rc = GetOptions ( $c, 'param1|p!', 'param2|P', 'paramN|n', ); # Write configuration state to disk $c->write; # simply get params back for use... do_something() unless $c->{param1}; # or get them more OO-ly if that makes you feel better my $value = $c->get_param2; METHODS
new Creates a new Config::YAML object. my $c = Config::YAML->new( config => initial_config, output => output_config ); The "config" parameter specifies the file to be read in during object creation. It is required, and must be the first parameter given. If the second parameter is "output", then it is used to specify the file to which configuration data will later be written out. This positional dependency makes it possible to have parameters named "config" and/or "output" in config files. Initial configuration values can be passed as subsequent parameters to the constructor: my $c = Config::YAML->new( config => "~/.foorc", foo => "abc", bar => "xyz", baz => [ 1, 2, 3 ], ); get_*/set_* If you'd prefer not to directly molest the object to store and retrieve configuration data, autoloading methods of the forms "get_[param]" and "set_[param]" are provided. Continuing from the previous example: print $c->get_foo; # prints "abc" my $val = $c->get_quux; # $c->{quux} doesn't exist; returns undef $c->set_bar(30); # $c->{bar} now equals 30, not "xyz" my @list = qw(alpha beta gamma); $c->set_baz(@list); # $c->{baz} now a reference to @list fold Convenience method for folding multiple values into the config object at once. Requires a hashref as its argument. $prefs{theme} = param(theme); $prefs{format} = param(format); $prefs{sortby} = param(order); $c->fold(\%prefs); my $format = $c->get_format; # value matches that of param(format) read Imports a YAML-formatted config file. $c->read('/usr/share/fooapp/fooconf'); "read()" is called at object creation and imports the file specified by "new(config=>)", so there is no need to call it manually unless multiple config files exist. write Dump current configuration state to a YAML-formatted flat file. $c->write; The file to be written is specified in the constructor call. See the "new" method documentation for details. DEPRECATED METHODS
These methods have been superceded and will likely be removed in the next release. get Returns the value of a parameter. print $c->get('foo'); set Sets the value of a parameter: $c->set('foo',1); my @paints = qw( oil acrylic tempera ); $c->set('paints', @paints); AUTHOR
Shawn Boyette ("<mdxi@cpan.org>") Original implementation by Kirrily "Skud" Robert (as "YAML::ConfigFile"). BUGS
o Config::YAML ignores the YAML document separation string ("---") because it has no concept of multiple targets for the data coming from a config file. Please report any bugs or feature requests to "bug-yaml-configfile@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. COPYRIGHT &; LICENSE Copyright 2004 Shawn Boyette, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-03-07 Config::YAML(3pm)
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy