LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2008, 10:00 AM   #1
ilo
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Rep: Reputation: 0
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.
 
Old 08-22-2008, 10:38 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SED/AWK help bioinformatics_guy Linux - Newbie 1 08-12-2008 05:07 AM
awk or sed help cmontr Programming 16 05-14-2008 10:59 AM
awk and/or sed linux2man Linux - General 7 01-22-2007 10:02 AM
Sed and Awk Gins Programming 7 04-19-2006 10:32 AM
awk/sed help pantera Programming 1 05-13-2004 11:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration