So I've created this ping sweep in a bash terminal, but I want to make a neat looking script file for this:
for IPs in 192.168.0.{1..254}; do ping -c1 -W1 $IPs; done | grep -B1 "1 received" | grep "192.168.0" | cut -d " " -f2 > BashPingSweep.txt
I think I have the for loop correct, but I cant pipe the for loop into the other greps and cut then output. This is what I have now:
#!/bin/bash
for IPs in 192.168.0.{1..254}
do
ping -c1 -W1 $IPs
done
grep -B1 "1 received"
grep "192.168.0"
cut -d " " -f2
> BashPingSweep.txt
grep/cutpair with a singleawkcommand:grep -B1 "1 received" | awk '/192.168.0/ {print $2}' > BashPingSweep.txt. (You could incorporate the othergrepinto the sameawkcommand, but that would take more work than would easily fit in a comment.)