to:
option domain-name-servers 166.2.100.32,166.6.4.100;
Yes I am a newbie.
#!/usr/bin/perl -w
use strict;
# Open input file in read mode
open INPUTFILE, "rich-input.txt", $ARGV[0] or die $!;
# Read the input file line by line :
while (my $input_line = <INPUTFILE>) {
$modif = "s/option domain-name-servers / bar /g";
if (preg_match('/option domain-name-servers/i', ) {(?=.*[a-z])(?=.*[A-Z])
preg_replace
If the command is fine, remove echo, and run again.
find /dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} !/^#/ {for (i in a) if ($0~i) sub(i ".fs.us.",a)}1' rich-input.txt "$line" > temp
echo mv temp "$line"
done
Thanks kindly for that shell script. However, I don't seem to get any results
bash-3.2# ./test.sh
mv temp dhcp/dhcp.in
drwxr-xr-x 6 richsark staff 204 Oct 28 22:26 .
drwxr-xr-x+ 22 richsark staff 748 Oct 28 22:23 ..
drwxr-xr-x 3 root staff 102 Oct 28 22:22 dhcp
-rw-r--r-- 1 richsark staff 188 Oct 28 22:18 rich-input.txt
-rw-r--r-- 1 root staff 0 Oct 28 22:26 temp
-rwxrwxrwx 1 richsark staff 180 Oct 28 22:22 test.sh
your code:
find dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} {for (i in a) if ($0~i) sub(i,a)}' rich-input.txt "$line" > temp
echo mv temp "$line"
done
You need update the patch for file rich-input.txt, then run the script by bash -x test.sh , paste the output here.
find /Users/richsark/test/dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} {for (i in a) if ($0~i) sub(i,a)}' rich-input.txt "$line" > temp
echo mv temp "$line"
done
cat temp
Just realize, Looks you don't use my code. the number 1 is missed, it is used to print the result to temp file
find /Users/richsark/test-US/dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} !/^#/ {for (i in a) if ($0~i) sub(i ".fs.us.",a)}1' rich-input.txt "$line" > temp
echo mv temp "$line"
done
I have been using your code. maybe I don't follow sorry
bash-3.2# cat test2.sh
find /Users/richsark/test-US/dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} !/^#/ {for (i in a) if ($0~i) sub(i ".fs.us.",a)}1' rich-input.txt "$line" > temp
echo mv temp "$line"
done
bash-3.2#
Ran code
bash-3.2# ./test2.sh
mv temp /Users/richsark/test-US/dhcp/dhcp.in
bash-3.2# ls -al
total 32
drwxr-xr-x 7 richsark staff 238 Oct 28 23:13 .
drwxr-xr-x+ 22 richsark staff 748 Oct 28 23:11 ..
drwxr-xr-x 3 root staff 102 Oct 28 22:48 dhcp
-rw-r--r-- 1 richsark staff 188 Oct 28 22:18 rich-input.txt
-rw-r--r-- 1 root staff 53 Oct 28 23:13 temp
-rwxrwxrwx 1 richsark staff 170 Oct 28 22:58 test.sh
-rwxrwxrwx 1 root staff 224 Oct 28 23:11 test2.sh
The actual files are modified and are present at the respective path!
Check this file on your system "/Users/richsark/test-US/dhcp/dhcp.in"
Don't remove the entire echo line... Use this...
find /Users/richsark/test-US/dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} !/^#/ {for (i in a) if ($0~i) sub(i ".fs.us.",a)}1' rich-input.txt "$line" > temp
mv temp "$line"
done
find /Users/richsark/test-US/dhcp -type f ! -name "*.bak" |while read line
do
awk 'NR==FNR{a[$1]=$2;next} !/^#/ {for (i in a) if ($0~i) sub(i ".fs.us.",a)}1' rich-input.txt "$line" > temp
# echo mv temp "$line"
mv temp "$line"
done