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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 12-19-2007
Tytalus's Unix or Linux Image
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 Unix and Linux 12-19-2007
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 27 March 2015, 11:47 AM EDT
Location: /dev/ph
Posts: 4,903
Thanks: 68
Thanked 450 Times in 418 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 Unix and Linux 12-19-2007
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 28 March 2015, 3:45 AM EDT
Location: Foxborough, MA
Posts: 7,764
Thanks: 170
Thanked 632 Times in 590 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 Unix and Linux 12-20-2007
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 27 March 2015, 11:47 AM EDT
Location: /dev/ph
Posts: 4,903
Thanks: 68
Thanked 450 Times in 418 Posts
Actually no. The -F: option is not required because of the space after the colon on each line.
Sponsored Links
    #6  
Old Unix and Linux 12-20-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 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 Unix and Linux 12-20-2007
invinzin21 invinzin21 is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 22 September 2014, 1:26 PM EDT
Location: Philippines, Cebu City
Posts: 88
Thanks: 4
Thanked 2 Times in 2 Posts
awk -F: '{print $2}' file
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 05:21 AM.