Sponsored Content
Top Forums Shell Programming and Scripting Find and replace a string on remote server Post 302607433 by nitinmathur18 on Wednesday 14th of March 2012 11:47:47 AM
Old 03-14-2012
I copied the script to the remote server and tested and it worked fine code is
Code:
#!/bin/ksh
find /devl/bfx/ecif/etl/visibility/parameterfiles/ -exec grep -l CNTCT {} \; | while read file
do ls -l $file
sed -e 's/CNTCT/CNTCTST/' $file> $file.tmp
mv $file.tmp $file
done
find /devl/bfx/ecif/etl/visibility/parameterfiles/ -exec grep -l DBCIBNR {} \; | while read file
do ls -l $file
sed  's/DBCIBNR/DBCIBC4/g' $file> $file.tmp
mv $file.tmp $file
done

when i tried the same from local i could not get the desired output.
main Code
Code:
#!/bin/bash
echo "Today is $(date)"
echo " This script will copy Prod Unix code into Breakfix Env."
echo "Choose Project: (1-18)"
echo " 1- CAM Extracts"
echo " 2- CASNCOA Extracts"
echo " 3- CDC Extracts"
echo " 4- CTMNZ Extracts"
echo " 5- CYBERLIFE  Extracts"
echo " 6- DW_ASCII_Conversion"
echo " 7- ECIF2CIFLOW"
echo " 8- ECIFNZ Extracts"
echo " 9- KEYNOTE Extracts"
echo " 10- NRS Extracts "
echo " 11- VANTAGE Extracts"
echo " 12- Prospects Extracts"
echo " 13- Visibility Extracts"
echo " 14- DW Extracts"
echo " 15- CASS MASN"
echo " 16- NWBank"
echo " 17- EASE"
echo " 18- Email Harvest"
echo " 19- CIM Stats Extract"
echo " 20- Change Identifier"
echo " 21- OFAC Extract"
echo " 22- Common Objects"
echo " 23- PLB Prefix Extract"
echo " 24- EDelivery Extract"
echo " 25- Farm Bureau Extract"
echo " 26- CNT Harvest"
echo " 27- AKM2ECIF"
echo " 28- CTM Claim Account Load"
echo " 29- Batch Processor"
echo " 30- Unload2MF"
echo " 31- ECIF_BATCHSTAT"
echo " 32- ALSEXTRACT"
echo " 33- SUPPORT"

echo "  ************************************"
echo ""
read Project
export Project1=$Project
case $Project in
        1) export Project=CAM_Extracts
	export ProjectTarget=camextract
        ;;
        2) export Project=casncoaext
	export ProjectTarget=casncoaext
        ;;
        3) export Project=cdcextract
	export ProjectTarget=cdcextract
        ;;
        4) export Project=ctmnzextract
	export ProjectTarget=ctmnzext
        ;;
        5) export Project=CYBERLIFE_EXTRACT
	export ProjectTarget=cyberlife
        ;;
        6) export Project=DW_ASCII_Conversion
	export ProjectTarget=dwascconv
        ;;
        7) export Project=ECIF2CIFLOW
	export ProjectTarget=ecif2ci
        ;;
        8) export Project=ecifnzext
	export ProjectTarget=ecifnzext
        ;;
        9) export Project=KEYNOTE_EXTRACT
	export ProjectTarget=keynote
        ;;
        10) export Project=NRS_EXTRACT
	export ProjectTarget=nrsextract
        ;;
        11) export Project=VANTAGE_EXTRACT
	export ProjectTarget=vantage
        ;;
        12) export Project=PROSPECTS_EXTRACT
	export ProjectTarget=prospects
        ;;
        13) export Project=visibility
	export ProjectTarget=visibility
        ;;
        14) export Project=dwextract
	export ProjectTarget=dwextract
        ;;
        15) export Project=cassmasn
	export ProjectTarget=cassmasn
        ;;
        16) export Project=nwbank
	export ProjectTarget=nwbank
        ;;
        17) export Project=ease
	export ProjectTarget=ease
        ;;
        18) export Project=emailharvest
	export ProjectTarget=emailharvest
        ;;
        19) export Project=cimstatsextract
	export ProjectTarget=cimstatsextract
        ;;
        20) export Project=changeid
	export ProjectTarget=changeid
        ;;
        21) export Project=ofacextract
	export ProjectTarget=ofacextract
        ;;
        22) export Project=common_objects
	export ProjectTarget=common_objects
        ;;
        23) export Project=plb_prefix_extract
	export ProjectTarget=plbextract
        ;;
        24) export Project=edelivery_extract
	export ProjectTarget=edelextrct
        ;;
        25) export Project=farm_bureau_extract
	export ProjectTarget=farm_bureau_extract
        ;;
        26) export Project=cntharvest
	export ProjectTarget=cntharvest
        ;;
        27) export Project=akm2ecif
	export ProjectTarget=akm2ecif
        ;;
        28) export Project=ctmclactld
	export ProjectTarget=ctmclactld
        ;;
        29) export Project=batchproc
	export ProjectTarget=batchproc
        ;;
        30) export Project=unload2mf
	export ProjectTarget=unload2mf
        ;;
	31) export Project=ECIF_BATCHSTAT
	export ProjectTarget=batchstats	
        ;;
	32) export Project=ALSEXTRACT
	export ProjectTarget=alsextract 
	;;
	33) export Project=support
	export ProjectTarget=support
        ;;
esac
case $Project1 in
        1) export Project=CAM_Extracts
	export ProjectTarget=camextract
	scp  ecifetls@boom.nwie.net:/vol/ecif/etl/$ProjectTarget/bin/*.* ecifetls@boom.nwie.net:/devl/bfx/ecif/etl/$ProjectTarget/bin/
	scp  ecifetls@boom.nwie.net:/vol/ecif/etl/$ProjectTarget/scriptfiles/*.* ecifetls@boom.nwie.net:/devl/bfx/ecif/etl/$ProjectTarget/scriptfiles/
	scp  ecifetls@boom.nwie.net:/vol/ecif/etl/$ProjectTarget/parameterfiles/*.* ecifetls@boom.nwie.net:/devl/bfx/ecif/etl/$ProjectTarget/parameterfiles/
	scp  ecifetls@boom.nwie.net:/vol/ecif/etl/$ProjectTarget/sql/*.* ecifetls@boom.nwie.net:/devl/bfx/ecif/etl/$ProjectTarget/sql/
	scp  ecifetls@boom.nwie.net:/vol/ecif/etl/$ProjectTarget/maestro/*.* ecifetls@boom.nwie.net:/devl/bfx/ecif/etl/$ProjectTarget/maestro/
	scp  ecifetls@boom.nwie.net:/vol/ecif/etl/$ProjectTarget/syncsort/*.* ecifetls@boom.nwie.net:/devl/bfx/ecif/etl/$ProjectTarget/syncsort/
	ssh  ecifetls@boom.nwie.net export "'$ProjectTarget'" < /webdata/ecif/etl/scripts/dbchange.sh ;;
esac

dbchange.sh
Code:
#!/bin/ksh

find /devl/bfx/ecif/etl/"${ProjectTarget}"/parameterfiles/ -exec grep -l "CNTCT" {} \; | while read file
do
     ls -l "${file}"
     sed -e 's/CNTCT/CNTCTST/g' "${file}" > "${file}.tmp"
     mv "${file}.tmp" "${file}" 
done
# 
find /devl/bfx/ecif/etl/"${ProjectTarget}"/parameterfiles/ -exec grep -l "DBCIBNR" {} \; | while read file
do
     ls -l "${file}"
     sed -e 's/DBCIBNR/DBCIBC4/g' "${file}" > "${file}.tmp" 
     mv "${file}.tmp" "${file}"
done

Here i m trying to copy file from Server1 Dir-1 to Server1 Dir-2 from Server2 and finding and replacing some string in parameter dir-2 of server1 .
 

10 More Discussions You Might Find Interesting

1. Programming

how to find and replace string

hi I wanted to find this char " ^M " in my file and replace it with blank space. I am using Unix system. If i give command " :%s/^M//gc " it wont work so can anyone tell what is command to find and replace thankx (3 Replies)
Discussion started by: mridula
3 Replies

2. Shell Programming and Scripting

Find files not accessed on a remote server and delete - Help!

Hi Guys, I am currently working on a script to find all the files that have not been accessed for the past 2 years. This, i guess has been discussed n number of times in this forum. Now, my requirement is to find all the files in the remote windows server. I have it mounted in unix. I was... (1 Reply)
Discussion started by: bond_bhai
1 Replies

3. UNIX for Dummies Questions & Answers

Find and replace character in a string

Hi all, My problem is the following: I've a script that must list all files in a directory and write this information in a text file. I've tried to get the list through ls command and then write it using msgecho msgecho "`ls $PATH_APS_JOB_ORA`" This works good but the created string... (7 Replies)
Discussion started by: callimaco0082
7 Replies

4. Shell Programming and Scripting

Find the position of a string and replace with another string

Hi, I have a file named "Test_2008_01_21" The file contains a string "manual" that occurs many times in the file How can i find the positions of the string "manual" in the file Ex: if the string " manual " occurs three times in the file. i want to replace the second occurance of string... (6 Replies)
Discussion started by: bab123
6 Replies

5. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

6. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

7. Solaris

How to find and replace a string?

Dear All I need to find and replace a string in a set of files. I try as : #find / -name "*"|xargs grep "Tektra"|grep -v "Tektra GSM BTS" But it doesn't work. It just finds the string in the files. I need to find and replace it.Can you please let me know how to correct it? Thank you (2 Replies)
Discussion started by: hadimotamedi
2 Replies

8. Shell Programming and Scripting

Find the remote server status.

Hi All, I would like to connect from "Instance A" to "Instance B" with the help of sftp. Where as Instance B is having clustered servers ( 2 servers pointing same instance ). Now, my question is before connecting to "Instance B" from "Instance A" how do know whether server is running or not.... (3 Replies)
Discussion started by: Girish19
3 Replies

9. UNIX for Dummies Questions & Answers

Find and Replace string in UNIX

Hi All, Greetings. I have a .dat file which somewhere in its content contains symbol ""^ I want to replace it with "^ I tried with SED command but could not achieve what i wanted sed -e "s/'""^'/'"^'/ig" filename.dat (5 Replies)
Discussion started by: MaddyS
5 Replies

10. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies
All times are GMT -4. The time now is 10:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy