Parse Line Using Sed | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Parse Line Using Sed

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-19-2007
racbern racbern is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 30 June 2011, 7:22 AM EDT
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Bug Parse Line Using Sed

Hello All,

I am new to using sed, and I need to extract from the string data after : delimeter.

Can you help me please with the sed command?

Here's the input:
ipAddress: 10.20.10.11
ioIpAddressNodeB: 10.20.10.10
ioIpAddressNodeA: 10.20.10.9
ipAddress: 0.0.0.0

Expected Output:
10.20.10.11
10.20.10.10
10.20.10.9
0.0.0.0

Thanks in advance to anyone who'll reply.

Regards,
racbern
Sponsored Links
    #2  
Old 12-19-2007
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
 
Join Date: Jun 2003
Last Activity: 10 January 2014, 5:37 AM EST
Location: Scotland
Posts: 594
Thanks: 1
Thanked 28 Times in 27 Posts
sed 's/.*://g'

should do you

or use awk:

awk '{FS=":";print $2}'

HTH
Sponsored Links
    #3  
Old 12-19-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 16 April 2014, 12:00 AM EDT
Location: /dev/ph
Posts: 4,711
Thanks: 54
Thanked 411 Times in 382 Posts
Here is one way of doing what you want using sed.


Code:
sed -n 's/^.*: \(.*$\)/\1/p'  yourfile

BTW, awk is probably a simpler tool to use for this type of task.


Code:
awk '{ print $2 }' yourfile

    #4  
Old 12-19-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 16 April 2014, 8:52 AM EDT
Location: Foxborough, MA
Posts: 7,523
Thanks: 137
Thanked 534 Times in 502 Posts
Quote:
Originally Posted by fpmurphy View Post
Here is one way of doing what you want using sed.


Code:
sed -n 's/^.*: \(.*$\)/\1/p'  yourfile

BTW, awk is probably a simpler tool to use for this type of task.


Code:
awk '{ print $2 }' yourfile

you forgot the FS definition:

Code:
awk -F: '{ print $2 }' yourfile

Sponsored Links
    #5  
Old 12-20-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 16 April 2014, 12:00 AM EDT
Location: /dev/ph
Posts: 4,711
Thanks: 54
Thanked 411 Times in 382 Posts
Actually no. The -F: option is not required because of the space after the colon on each line.
Sponsored Links
    #6  
Old 12-20-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 7 November 2013, 6:42 AM EST
Posts: 2,651
Thanks: 0
Thanked 16 Times in 16 Posts
shell

Code:
#!/bin/sh
while IFS=: read one two
do
    echo $two
done < file

output:

Code:
# ./test.sh
10.20.10.11
10.20.10.10
10.20.10.9
0.0.0.0

Sponsored Links
    #7  
Old 12-20-2007
invinzin21 invinzin21 is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 13 March 2014, 11:37 AM EDT
Location: Philippines, Cebu City
Posts: 86
Thanks: 4
Thanked 2 Times in 2 Posts
awk -F: '{print $2}' file
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To parse the line julie_s Shell Programming and Scripting 2 08-27-2009 05:33 AM
how do you parse 1 line at a time of file1 ie. line(n) each line into new file web_developer UNIX for Advanced & Expert Users 4 06-28-2009 12:07 PM
SED help (remove line::parse again::add line) Malumake Shell Programming and Scripting 6 10-24-2007 05:02 PM
please help to parse the line ajaya Shell Programming and Scripting 1 05-10-2006 09:11 AM
How to parse a line? edefoe Shell Programming and Scripting 2 12-22-2005 05:23 PM



All times are GMT -4. The time now is 09:13 AM.