LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-15-2003, 05:21 PM   #1
Pauly
LQ Newbie
 
Registered: Jan 2002
Posts: 16

Rep: Reputation: 0
Lightbulb Need suggestions for parsing a shell variable


Hello,

I need some suggestions. I have a script that will ask the user for an ip address, which is entered by keyboard

ie: echo "What is your IP?"
read IPADDRESS

I then need to parse the IP address for the number in its 4th octet and store it to a another varilable. For example, if my IP is 192.168.128.4, I need to store the value 4 in a variable.

Cheers,

and thanks for any help offered!
 
Old 01-15-2003, 07:32 PM   #2
nxny
Member
 
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771

Rep: Reputation: 30
fouthoctet=$(echo $ipaddress | awk -F. '{ print $NF }')

Note: Assumes a valid ip address.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
(shell script) string parsing kuru Programming 4 09-12-2005 07:59 PM
Script File: Parsing command sent to shell cheema Programming 1 07-01-2005 12:54 PM
[c shell] variable question saiz66 Programming 5 09-29-2004 09:45 AM
parsing a variable using linux shell philco Programming 6 09-04-2003 06:52 PM
File Parsing using a Shell Script yasir15 Programming 5 08-22-2003 12:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:39 PM.

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