LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 11-21-2002, 02:24 PM   #1
Harpune
Member
 
Registered: Sep 2002
Location: Seattle, WA
Distribution: Ubuntu
Posts: 101

Rep: Reputation: 15
Post file editing in a bash script


I have a file that looks like this:

User fu (UID=xxx) logged on foo.bar.edu (666.666.666.666) at 18:43:27 10.21.2002
User foo (UID=xxx) logged on bar.bar.edu (666.666.666.555) at 2:17:32 10.23.2002
User bah (UID=xxx) logged on fu.bar.edu (666.666.666.444) at 4:38:52 11.02.2002

And i need to cut all the text up to the first parenthese and after the second parenthese so i get a list like this:

666.666.666.666
666.666.666.555
666.666.666.444

How would i go about doing that in a bash script?
 
Old 11-21-2002, 03:17 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
easiest way i'd say was to just use a simple sed statement in a loop:

sed 's/.*(\([0-9.]*\).*/\1/'

that'll leave you with just the ip when the entire string is piped through it.
 
Old 11-21-2002, 04:32 PM   #3
Harpune
Member
 
Registered: Sep 2002
Location: Seattle, WA
Distribution: Ubuntu
Posts: 101

Original Poster
Rep: Reputation: 15
sweet action.

thanks for the help
 
Old 11-22-2002, 11:30 PM   #4
Harpune
Member
 
Registered: Sep 2002
Location: Seattle, WA
Distribution: Ubuntu
Posts: 101

Original Poster
Rep: Reputation: 15
btw, I am relatively new to some shell commands.. I couldn't figure out exactly what that command did. where can I get a good reference on the sed command?

thanks again
 
Old 11-23-2002, 12:35 AM   #5
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
http://www.oreilly.com
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Parsing a File in a Bash Script TGWDNGHN Programming 4 12-02-2005 03:38 PM
making a bash script file Berticus Linux - General 1 10-16-2005 12:14 AM
[bash] removing or editing lines in file Erhnam Programming 12 03-15-2005 08:25 AM
reading file, bash script marri Programming 3 11-15-2004 10:13 AM
Can't get lines of a file with a Bash script.. barisdemiray Programming 2 08-11-2004 01:42 PM


All times are GMT -5. The time now is 01:13 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration