| | |
file replacement not working!
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hi Team,
I am stuck in a very tight situation.. need your help
The below script does not work even please let me know where is the problem and rectify me.
Script as below:
replace.sh
1)Here the file_name stands for file name
2)old_templet stands for old word to change
3)new_templet stands for new word
But when the script it gives me the below error:
./replace.sh one single oracle
cat: file_name: No such file or directory
Thanks for your patience..
hope 4 a speedy reply
cheers!
Whizkidash
I am stuck in a very tight situation.. need your help
The below script does not work even please let me know where is the problem and rectify me.
Script as below:
replace.sh
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/bash file_name=$1 old_templet=$2 new_templet=$3 for file in file_name do cat $file | sed "s/old_templet/new_templet/g" > $file.new done
1)Here the file_name stands for file name
2)old_templet stands for old word to change
3)new_templet stands for new word
But when the script it gives me the below error:
./replace.sh one single oracle
cat: file_name: No such file or directory
Thanks for your patience..
hope 4 a speedy reply
cheers!
Whizkidash
Last edited by peter_budo; Nov 9th, 2009 at 5:34 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
1
#2 Nov 9th, 2009
$file_name, not file_name
ditto for the other variables
use "sed -e" not just "sed"
and change $file.new to ${file}.new just to be safe
Edit: So many problems, so little text. ;-)
ditto for the other variables
use "sed -e" not just "sed"
and change $file.new to ${file}.new just to be safe
Edit: So many problems, so little text. ;-)
Last edited by masijade; Nov 9th, 2009 at 3:20 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
1
#3 Nov 9th, 2009
Masijade answered your question but i'd like to throw something else in there. You should add checks for your arguments on the command line and verify the file exists:
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/bash file_name=$1 old_templet=$2 new_templet=$3 if [ "$3" = "" ]; then echo "usage: ${0} <file_name> <new_templet> <old_templet>" exit 1 fi if ! test -f ./${file_name}; then echo "file not found" exit 1 fi if test -f ./${file_name}.new; then rm ./${file_name}.new fi sed "s/${old_templet}/${new_templet}/g" ${file_name} >> ${file_name}.new
Last edited by sknake; Nov 9th, 2009 at 5:17 am.
![]() |
Similar Threads
- HP Pavilion ze5155 BIOS problem... (Troubleshooting Dead Machines)
- Binary file I/O using fstreams - why not working? (C++)
- ASP: Deleting a file (ASP)
- File input. (C++)
- Python and the JPEG Image File, Part 2, The Image (Python)
- Yikes! Lost File & Program Associations! W2K (Windows NT / 2000 / XP)
- Help with .js JAVASCRIPT file!!!!!?!!?!? (JavaScript / DHTML / AJAX)
- File Processing 2 (C)
- File Handling Help NEEDED (PHP)
- file sharing (Windows NT / 2000 / XP)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell script to append text file with today's date.
- Next Thread: OMG... simple question driving me nuts
Views: 716 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






