LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-07-2009, 04:58 PM   #1
gankoji
Member
 
Registered: Nov 2007
Location: Southern California
Distribution: Slackware-13.0 x86_64, Slackware 12.2, slackware64-current
Posts: 225

Rep: Reputation: 35
Bash script using sed - how to pick something out of a file?


Aloha fellow slackers -

I'm currently setting up remote access to my email server so that clients can get their email from home/wherever they'd like to be. I've got it working, but I'm on a DSL/DHCP line here and am using DynamicDNS to support it. For the moment, I've simply told postfix to allow relay access from my network name (which is of the format pool-IP-Address-.lsanca.dsl-w.verizon.net) until I can figure out a better way. Since I have dynamic dns already and ddclient running to constantly update my domain name, I'm trying to write a script that takes the output of ddclient -query, which spouts out some data including my current public IP, and route it into the postfix/main.cf file using the combo of sed and postconf commands.

My question is this: I've spent about an hour or two now looking through the sed man page and textinfo documentation and can't figure out how to extract just the IP address from ddclient's output. I envision it something like this in the script:

postconf -e "my_networks=pool-`ddclient -query | sed -[I]some command[I] /regexpForIP/`.lsanca.dsl-w.verizon.net";

I know it's a bit convoluted but to me it seems like the best idea at the moment.
 
Old 08-07-2009, 05:28 PM   #2
Perceptor
Member
 
Registered: Jul 2007
Location: the Future
Distribution: Slackware
Posts: 128

Rep: Reputation: 64
sed s/[^0-9.]//g
 
Old 08-07-2009, 05:43 PM   #3
gankoji
Member
 
Registered: Nov 2007
Location: Southern California
Distribution: Slackware-13.0 x86_64, Slackware 12.2, slackware64-current
Posts: 225

Original Poster
Rep: Reputation: 35
So that command would replace every character that's not a number with nothing so that I only end up with numbers? except that it has the . character so I'm not really sure what that intends to accomplish. What would that do?
 
Old 08-07-2009, 06:14 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by Perceptor View Post
sed s/[^0-9.]//g
The logic of this SED command is: "on each line of the file, delete the first instance of any character that is not either a numeral or a period."

I do not understand how that relates to OP's question.....!!!


Here is an incompletely de-bugged IP detector. In this case, it's just deleting all lines that don't contain an IP. It fails--e.g.-- on something like 137.56.23.4567

sed -r '/([0-9][0-9]?{2}\.){3}[0-9][0-9]?{2}/!d'

There are other threads here at LQ with examples of Regexes to find valid IPs.
 
Old 08-07-2009, 06:15 PM   #5
gankoji
Member
 
Registered: Nov 2007
Location: Southern California
Distribution: Slackware-13.0 x86_64, Slackware 12.2, slackware64-current
Posts: 225

Original Poster
Rep: Reputation: 35
Thanks pixellany!
 
  


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
Bash script help... menu to pick file from folder bfellenr Linux - Newbie 13 01-15-2011 03:30 PM
bash script using sed/scp/ssh has issues with delimited file ScottThornley Programming 5 03-18-2009 03:45 PM
Sed doesn't update file in bash script chilebiker Programming 4 06-14-2007 08:25 AM
howto pick bash variables from file imagineers7 Linux - Newbie 3 05-08-2006 01:56 AM
sed in small BASH script OhLordy Linux - General 1 08-29-2003 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:54 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