cp & sed error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp & sed error
# 1  
Old 02-06-2006
cp & sed error

Hi,
Below is a small piece of my Korn shell script - what i am trying to do is substitute all occurrences of the word given by the ${src} parameter with the word given by the ${dest} parameter in that particular textfile. But i get the errors below...

Code:
for i in `ls $ORACLE_BASE/admin/${dest}/pfile/`
do
  echo "replacing ${src} to ${dest} for $i"
  cp $i $ORACLE_BASE/admin/${dest}/pfile/$i_backup
  cat $i_backup | sed -e "/s/${src}/${dest}/g" > $i
  rm -f $i_backup
done


cp: cannot access init.ora.162006124556
sed: command garbled: /s/db1/db2/g

Can someone let me know what's wrong with my code, and help me solve the problem?
Thanks!
# 2  
Old 02-06-2006
Quote:
Originally Posted by n8575
Code:
for i in `ls $ORACLE_BASE/admin/${dest}/pfile/`
do
  echo "replacing ${src} to ${dest} for $i"
  cp $i $ORACLE_BASE/admin/${dest}/pfile/$i_backup
  cat $i_backup | sed -e "/s/${src}/${dest}/g" > $i
  rm -f $i_backup
done


cp: cannot access init.ora.162006124556
sed: command garbled: /s/db1/db2/g

Can someone let me know what's wrong with my code, and help me solve the problem?
Thanks!
Remove the / before "/s/..." and enclose all the names within " "

Try this.

Code:
for i in `ls -1 $ORACLE_BASE/admin/${dest}/pfile/`
do
  echo "replacing ${src} to ${dest} for $i"
  cp "$i" "$ORACLE_BASE/admin/${dest}/pfile/$i_backup"
  sed -e "s/${src}/${dest}/g"  "$i_backup" > $i
  rm -f "$i_backup"
done

# 3  
Old 02-06-2006
I still get the same cp error, and another error which i have no idea what it is referring to...

cp: cannot access init.ora.162006131752
First RE may not be null

The sed command still didnt work - the words weren't substituted.
Help! Smilie
# 4  
Old 02-06-2006
This should work. You were looking for $ORACLE_BASE/admin/${dest}/pfile/$i elsewhere.

Code:
for i in `ls -1 $ORACLE_BASE/admin/${dest}/pfile/`
do
  echo "replacing ${src} to ${dest} for $i"
  sed -e "s/${src}/${dest}/g"  "$ORACLE_BASE/admin/${dest}/pfile/$i" > "$ORACLE_BASE/admin/${dest}/pfile/$i_new"
  mv "$ORACLE_BASE/admin/${dest}/pfile/$i_new" "$ORACLE_BASE/admin/${dest}/pfile/$i"
done


Last edited by vino; 02-06-2006 at 10:54 AM.. Reason: Removed an extra command.
# 5  
Old 02-06-2006
It still didnt work Smilie I get a whole lot of the same type of error as shown below...

replacing db1 to db2 for total
./createdb.sh[135]: /u01/app/oracle/admin//pfile/: cannot create
mv: cannot access /u01/app/oracle/admin//pfile/

by the way, why use ls -l in the for loop, instead of just ls?
# 6  
Old 02-06-2006
Code:
sed -e "s#${src}#${dest}#g"  "$i_backup" > $i

# 7  
Old 02-06-2006
Also didnt work Smilie
I even tried to do just the sed command, without the cp or mv commands coz those were giving errors, but the sed still didnt do it's job :S
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Echo "abc" | sed - r 's/a/&_&/

I want to know the working of & here step by step using sed command. (1 Reply)
Discussion started by: Preeti07
1 Replies

2. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

3. Shell Programming and Scripting

if statement with '&&' gives error

Hi, I'm using the && operator in if statement: if ; then exp $UID/$PWD@$ORACLE_SID FILE=./DUMP/$TODAY$CONCAT_STR$USERNAME.dmp STATISTICS=NONE LOG=./LOG/$TODAY$CONCAT_STR$USERNAME.log elif ; then expdp $UID/$PWD@$ORACLE_SID DIRECTORY=./DUMP/ DUMPFILE=$TODAY$CONCAT_STR$USERNAME.dmp... (8 Replies)
Discussion started by: priya001
8 Replies

4. Shell Programming and Scripting

Help with sed ( & )

I am searching for a specific pattern and replacing with ( ) for matched pattern .I am not getting the expected result ..... Here is the file cat test cool change Frinto Francis Frinto cool change Attitude /usr/bin sed 's/*/( & )/' test ( cool ) ( change ) ( )Frinto Francis... (2 Replies)
Discussion started by: frintocf
2 Replies

5. Shell Programming and Scripting

Perl & Sed command -- Out of Memory Error

Experts, We used to receive our source files with '~^' as row delimiter. This file contains 2500K records and two of the columns having value in HTML formats within the file. While running the below commands against the file, we are encountering out of memory, could you please help to... (3 Replies)
Discussion started by: srivijay81
3 Replies

6. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

7. UNIX for Dummies Questions & Answers

Question: Help need to remove blank line & sed: Couldn't re-allocate memory error.

I've shell script where i used the below command to take the line which contains patterns. sed -n "/$year 05:/,/$year 17:/p" trace.log | grep -f patterns.txt > output.log This was working fine for long time, but now a days this script is not working with and throwing error like sed:... (8 Replies)
Discussion started by: senthil.ak
8 Replies

8. Shell Programming and Scripting

Help, | ! & [ ^ in sed

Hi,everyone: I'm new to shell, and I'm confued with some script: ssum=`echo "$lsum" | sed 's|!|\\\\!|g'` line1=`echo "$line" | sed 's!\!\\\]!g'` line3=`echo "$line2" | sed 's!\&!\\\&!g'` sed "s^${line3}^${newline3}^g" ${TIER4FILE} > ${TMP_TIER4FILE} In the first three lines,... (5 Replies)
Discussion started by: mycoy
5 Replies

9. Linux

Kernal panic error& setuproot:error mounting /proc&/sys

Hi all, I am new to redhat/fedora linux. In fedora linux 6,we created one file system(hda3 - /fs). in this mount poing we were installed mounta vista os. while booting we are getting below error messages. 1) Booting 'mountaVisat(2.6.18_pro 500_pc_target-x86_586 smp)' root(hd0,1)... (2 Replies)
Discussion started by: arjunreddy3
2 Replies

10. Shell Programming and Scripting

sed & awk

Hi. I'm going to learn scripting and i have the following topics on the list: sed, awk, shell scripting, perl. My question is, whehter i should learn sed and awk? Aren't this tools outdated? Although i see that GNU upgrade it's versions of these tools from time to time. And, the next... (9 Replies)
Discussion started by: kukuruku
9 Replies
Login or Register to Ask a Question