tags:

views:

870

answers:

4

I am using shell script. How to copy one file content to another file using "sed". I have to use only sed to complete this copy. can anyone help me?

Thanks in advance Sudha

A: 

sed writes its output on standard output, not in a file. You have to use redirections. One possible command is:

sed -n 'p' myInFile > myOutFile
mouviciel
A: 

All you need is a noop:

sed -e '' <"${OLDNAME}" >"${NEWNAME}"

...that said, why? Most tiny embedded systems will be using busybox, and while they may not have cp (hey, I've built a busybox without one for a dedicated router appliance!), not adding cat to the busybox config is just silly.

Charles Duffy
A: 

As suggested, you can do this with sed, but why not simply copy the file with the cp command?

anon
That much I can understand -- cp isn't a shell builtin, and so may not be available in embedded systems either (1) not using busybox or (2) with an extremely cut-down busybox. Granted, sed isn't either, but it may already be installed for other reasons. Still silly -- the shell alone is enough.
Charles Duffy
+1  A: 

If you actually wanted to use the write functionality in sed, you could use the w command to write to a specific file

sed -n "w$NEWNAME" $OLDNAME
Beano