problems using awk in a bash program???
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > problems using awk in a bash program???




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    problems using awk in a bash program???  
Peter Taylor


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-04 09: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







[ Post a follow-up to this message ]



    Re: problems using awk in a bash program???  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-04 09: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 on
ce
> 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





[ Post a follow-up to this message ]



    Re: problems using awk in a bash program???  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-04 09: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 on
ce
> 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.





[ Post a follow-up to this message ]



    Re: problems using awk in a bash program???  
Peter Taylor


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-04 02:37 AM


"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 
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[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;;







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:33 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register