find and sed comand for Solaris 9


 
Thread Tools Search this Thread
Operating Systems Solaris find and sed comand for Solaris 9
# 1  
Old 03-06-2009
find and sed comand for Solaris 9

Hi,

I'm looking to combine the two commands find and sed together for the work that i'm worknig on.
I need to find the ip addresse in any file from current directory and below, once is found i need to replace it with new ip addresse. Here is what i have but not complete.

Find IP from current directory to sub-directory
#find . -type f |xargs grep -l "10.117.18.70"

My script can only change ip that found in current directory but not sub-directory. I want to combine the find and this sed in script.

#!/bin/bash
for fl in *.* ; do

mv $fl $fl.old
sed 's/10.117.18.70/10.117.18.73/g' $fl.old > $fl
rm -f $fl.old
done

Thanks
# 2  
Old 03-06-2009
This should do the trick

Code:
#!/bin/bash
for fl in `find . -type f` ; do

mv $fl $fl.old
sed 's/10.117.18.70/10.117.18.73/g' $fl.old > $fl 
rm -f $fl.old
done

# 3  
Old 03-06-2009
Thanks a lot. I't working great.
# 4  
Old 03-06-2009
find and sed for Solaris 9

Hi,
Now my script is working fine. When i run it it change the owner to root if root isthe one to run, i guess because of the command mv. How to keep the files attributes the same after running this script. Any thought?

Thanks again.

#!/bin/bash
for fl in `find . -type f` ; do

mv $fl $fl.old
sed 's/10.117.18.70/10.117.18.73/g' $fl.old > $fl
rm -f $fl.old
done
# 5  
Old 03-06-2009
mv doesn't change ownership.

Code:
sed 's/10.117.18.70/10.117.18.73/g' $fl.old > $fl 

It's when you creating the new file. Just run the script as the current owner of the file.

Or you can complexify you script...

Code:
#!/bin/bash
for fl in `find . -type f` ; do
   owner=`ls -al $fl | awk '{printf "%s:%s",$3,$4}'`
   mv $fl $fl.old
   sed 's/10.117.18.70/10.117.18.73/g' $fl.old > $fl 
   rm -f $fl.old
   chown $owner $fl
done


Last edited by ce9888; 03-06-2009 at 01:00 PM.. Reason: wasn't working. this one works
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find comand directories permissions

Hi, In the code below, while the "xarsg" command does not search in "tavi_valo" subdir? IAB00201:UG02222:EXPL> ls -1|xargs -IXX find XX -name tv_va_servbonos 2>/dev/null UG02222/fuentes/TAVA/TAVA4E0000/backup/tv_va_servbonos... (2 Replies)
Discussion started by: Jose Luis
2 Replies

2. Shell Programming and Scripting

UNIX comand

Team, I need unix command to grep directory part from the string for example I have a texts something like /apps/opt/data/current/spool/test.dbf /apps/opt/archive/../../test.dbf I need only directory part from that string like my out put will /apps/opt/data/current/spool/... (1 Reply)
Discussion started by: asappidi
1 Replies

3. Solaris

Find and sed for an email address in Solaris 10

in Solaris 10 I am able to run: find . -type f -name "copy*" exec grep example.com {} \; and I get results. but when I try to find and sed: find . -type f -name "copy*" exec sed -e 's/user@example\.com/user2@example\.com' {} \; the command executes correctly but doesn't change... (6 Replies)
Discussion started by: os2mac
6 Replies

4. Solaris

Is it possible to find the seek rate of the find command in Solaris?

Hello, I am running some performance based tests on Solaris, and I was wondering how fast the "seeking" rate of Solaris is, or how fast Solaris can get information about files with the "find" command. Does anyone know what 'find' command I could run to traverse through my system to see the rate... (1 Reply)
Discussion started by: bstring
1 Replies

5. Shell Programming and Scripting

Find and Rename files using (find mv and sed)

In response to a closed thread for degraff63 at https://www.unix.com/shell-programming-scripting/108882-using-mv-find-exec.html the following command might do it as some shells spit it without the "exec bash -c " part: Find . -name "*.model" -exec bash -c "mv {} \`echo {} | sed -e 's//_/g'\`"... (0 Replies)
Discussion started by: rupert160
0 Replies

6. Solaris

Using dd comand

Hello peolple i have to check a tape with de dd comand and redirect the exit dd if=/dev/rmt/0cn ibs=1024k of=/dev/null i need that the exit from that commando go to a log if a do this dd if=/dev/rmt/0cn ibs=1024k of=/dev/null > x.log don`t send me nothing to the log only in the screen. I need... (1 Reply)
Discussion started by: enkei17
1 Replies

7. Solaris

comand df -k

I need to know the available space in my unix. when making a df -k it shows me the following thing: /dev/vx/dsk/emc2/vol06 136764867 121542767 1545614 99% /emc06 would need them to explain to me well the command. since under the column avail the resulting value is... (2 Replies)
Discussion started by: roviedo
2 Replies

8. UNIX for Dummies Questions & Answers

exec comand

hi, i have written a small script in which i use exec command and redriect output to a file..after sometime i want to switch it off and redirect the output to screen..how to do it exec >> /tmp/out.txt 2>&1 //set of statements then i want to switch of these exec as the rest should get... (5 Replies)
Discussion started by: mkan
5 Replies

9. UNIX for Dummies Questions & Answers

mount comand

Dear experts: I am installing software on Unix via telnet using CD on my NT workstation. What kind of NFS & mount comands I should run in the beginning ? (what exactly should be <drive for cdrom> and <mount ditectory> in the mount comand? Thanks in advance, etc.. (6 Replies)
Discussion started by: lostam
6 Replies
Login or Register to Ask a Question