Hi everyone.
I try to replace lot of network mask in many files and after hours I am blocked, I am stupid with sed. This is my goal:
I would like to replace every
and this to every netmask ( 32 to 1) in every file (text files with .ip4 extension) inside a folder. I try different logic like:
but in my case I don't want to specify the name of the file. I would like to do it in every file inside a folder and the most important: how can I replace 32 times some "words" in the same file and do it recursively for every file (text files only) in the folder. I'm blocked to use the tempfile in a "clever" way.
I am not a developer and I know my logic is bad to do this task. If somebody can help me to understand the good way to do this he will make me very happy. It is to use it with my FreeBSD router as file tables.
Thank you so much for your time.
Clem
I try to replace lot of network mask in many files and after hours I am blocked, I am stupid with sed. This is my goal:
I would like to replace every
Code:
255.255.255.255 by 32
255.255.255.254 by 31
255.255.255.252 by 30
255.255.255.248 by 29
255.255.255.240 by 28
etc..
Code:
#!/bin/sh
echo enter file name with extension
read NAME
echo enter word to replace
read FIND
echo enter word that replaces
read REPLACE
for file in $(/usr/bin/grep -il "$FIND" $NAME)
do
sed -e "s/$FIND/$REPLACE/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done
I am not a developer and I know my logic is bad to do this task. If somebody can help me to understand the good way to do this he will make me very happy. It is to use it with my FreeBSD router as file tables.
Thank you so much for your time.
Clem