|
Home > Archive > Unix Programming > March 2004 > problems using awk in a bash program???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problems using awk in a bash program???
|
|
| Peter Taylor 2004-03-17, 4:41 pm |
| Hi,
I'm fairly new to shell programming so this is hopefully just a simple
syntax error.
What I'm trying to do is to get an ip address from "file1.txt", ping it once
and put this in "file2.txt". Here's my code:
address = awk $1 file1.txt;
ping "$address"-c 1 >> file2.txt;
echo
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~">>file2.txt;;
can anybody tell me where I'm going wrong?
file1.txt is set out as below:
192.168.0.1
192.168.0.2
13.65.98.2
255.255.25.255
156.285.24.2
1.2.3.4
etc... jus a list of IP addresses, each on a new line in dotted decimal
form.
and hopefully file2 will look like this:
PING 192.168.0.1 (192.168.0.1) from 192.168.0.2 : 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=128 time=0.214 ms
--- 192.168.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% loss, time 0ms
rtt min/avg/max/mdev = 0.214/0.214/0.214/0.000 ms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
PING 192.168.0.2 (192.168.0.2) from 192.168.0.2 : 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=128 time=0.214 ms
--- 192.168.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% loss, time 0ms
rtt min/avg/max/mdev = 0.214/0.214/0.214/0.000 ms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
PING 13.65.98.2 (13.65.98.2) from 192.168.0.2 : 56(84) bytes of data.
64 bytes from 13.65.98.2: icmp_seq=1 ttl=128 time=0.214 ms
--- 13.65.98.2 ping statistics ---
1 packets transmitted, 1 received, 0% loss, time 0ms
rtt min/avg/max/mdev = 0.214/0.214/0.214/0.000 ms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
and so on...
any help would be much appreciated.
thanks for any replies
Pete
| |
| Måns Rullgård 2004-03-17, 4:41 pm |
| "Peter Taylor" <peter_neal_taylor@tiscali.co.uk> writes:
> Hi,
> I'm fairly new to shell programming so this is hopefully just a simple
> syntax error.
>
> What I'm trying to do is to get an ip address from "file1.txt", ping it once
> and put this in "file2.txt". Here's my code:
>
> address = awk $1 file1.txt;
> ping "$address"-c 1 >> file2.txt;
> echo
> " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~">>file2.txt;;
>
> can anybody tell me where I'm going wrong?
>
> file1.txt is set out as below:
> 192.168.0.1
> 192.168.0.2
> 13.65.98.2
> 255.255.25.255
> 156.285.24.2
> 1.2.3.4
>
> etc... jus a list of IP addresses, each on a new line in dotted decimal
> form.
>
> and hopefully file2 will look like this:
>
> PING 192.168.0.1 (192.168.0.1) from 192.168.0.2 : 56(84) bytes of data.
> 64 bytes from 192.168.0.1: icmp_seq=1 ttl=128 time=0.214 ms
>
> --- 192.168.0.1 ping statistics ---
> 1 packets transmitted, 1 received, 0% loss, time 0ms
> rtt min/avg/max/mdev = 0.214/0.214/0.214/0.000 ms
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~
> PING 192.168.0.2 (192.168.0.2) from 192.168.0.2 : 56(84) bytes of data.
> 64 bytes from 192.168.0.2: icmp_seq=1 ttl=128 time=0.214 ms
>
> --- 192.168.0.2 ping statistics ---
> 1 packets transmitted, 1 received, 0% loss, time 0ms
> rtt min/avg/max/mdev = 0.214/0.214/0.214/0.000 ms
You'll need a loop to do that. Something like this:
while read address; do
ping -c1 $address
echo "~~~~~~~~~~~~~~~~~~"
done < file1.txt > file2.txt
--
Måns Rullgård
mru@kth.se
| |
| William Park 2004-03-17, 4:41 pm |
| Peter Taylor <peter_neal_taylor@tiscali.co.uk> wrote:
> Hi,
> I'm fairly new to shell programming so this is hopefully just a simple
> syntax error.
>
> What I'm trying to do is to get an ip address from "file1.txt", ping it once
> and put this in "file2.txt". Here's my code:
>
> address = awk $1 file1.txt;
> ping "$address"-c 1 >> file2.txt;
> echo
> " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~">>file2.txt;;
Hints:
for i in `cat file1.txt`; do
...
done > file2.txt
or
while read i; do
...
done < file1.txt > file2.txt
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data processing and document management.
| |
| Peter Taylor 2004-03-17, 9:37 pm |
|
"William Park" <opengeometry@yahoo.ca> wrote in message
news:c3ag15$26o9e3$1@ID-99293.news.uni-berlin.de...
> Peter Taylor <peter_neal_taylor@tiscali.co.uk> wrote:
once[color=darkred]
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[colo
r=darkred]
>
> Hints:
> for i in `cat file1.txt`; do
> ...
> done > file2.txt
> or
> while read i; do
> ...
> done < file1.txt > file2.txt
>
> --
> William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
> Linux solution for data processing and document management.
sorted, thanks very much.
I ended up with:
for i in `cat file1.txt $1`; do
ping $i -c 1;
done >> file2.txt;;
|
|
|
|
|