The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 04-22-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 740
The script removes the temporary file we are going to use, ensuring it is not a symbolic link pointing elsewhere, the the sed line does:
for every line in abc.sh it looks for
192.168.1.4 and replaces it with v5c0 however many times 192.168.1.4 occurs in each line, without the "g" only the first occurrence in each line would get replaced, and: sed looks for 192.168.1.41 and replaces and replaces it with acc1 however many times it repeated in each line,
the output from sed is put into a temporary file because normal text processing commands cannot write back to the file they are reading from without corrupting them, the temporary filename is abc.sh. with the PID of the script added on the end to make it unique, the ">" means that if abc.sh.$$ already existed it will get overwritten, if the sed does not fail (the && test) then the next command is run which is to copy the temporary file back to the original, copying the temporary file rather than moving it preserves the permissions of abc.sh, if the copy is successful then the temporary file is deleted.