LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed or awk (https://www.linuxquestions.org/questions/programming-9/sed-or-awk-664610/)

ilo 08-22-2008 10:00 AM

sed or awk
 
Hello All, I am trying to program a script to change the ip.

I would like that the user enters 67.50.25.25
and since we use /24 masks I can just "calculate" from sed or awk

the gateway 67.50.25.1 the network 67.50.25.0 and the broadcast 67.50.25.255.

Any help would be appreciated.

matthewg42 08-22-2008 10:38 AM

You can do this quite easily with a shell script and internal string manipulation - no need to invoke other processes:
Code:

#!/bin/bash

read -p "enter the IP> " ip
slash24root="${ip%.*}"
gateway="$slash24root.1"
network="$slash24root.0"
broadcast="$slash24root.255"

printf "%-20s = %s\n" "ip" "$ip"
printf "%-20s = %s\n" "gateway" "$gateway"
printf "%-20s = %s\n" "network" "$network"
printf "%-20s = %s\n" "broadcast" "$broadcast"



All times are GMT -5. The time now is 12:35 AM.