fedora
1
Hey guys, seems I can't transfer the $ip into gawk in the following bash script, where the problem is?
#!/bin/bash
while read ip
do
gawk '$1~"$ip"' /tmp/source
done < /tmp/ip
++
cat /tmp/ip
192.16.1.1|192.168.1.2|192.168.1.3
10.1.1.1|10.1.1.2
10.8.1.0|10.8.1.1|10.8.1.2
--
cat /tmp/source
192.1.1.1 192.1.2.5 a
10.1.1.1 192.1.1.1 b
.....
Thank you!
anbu23
2
gawk '"'$1'" ~ "'$ip'"' source
fedora
3
hello anbu23, thank you for your reply, but it does not work, I already double checked.
and btw, do you have some recommendation reading on this? transfer variable within shell script?
anbu23
4
try this
gawk -v par="$1" -v ipaddr="$ip" ' par ~ ipaddr ' source
anbu23
5
fedora
6
hate to say this, but still it does not work.
I will dig up the link
anbu23
7
use awk. if it still doesn't work show us the trace of script
fedora
8
error messages go like this,
--
awk: syntax error near line 1
awk: bailing out near line 1
fedora
9
AH, thank you for your link, anbu23
using awk like this will work!
awk '$1~ /'"$ip"'/' sourcefile
fedora
11
sure, anbu23, as follow,
#!/bin/bash
while read hosts
do
echo $hosts
awk '$1~ /'"$hosts"'/' /tmp/source > /tmp/$hosts.src
done < /tmp/test
anbu23
12
i didn't see this message .