The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parsing a string in a shell script asutoshch Shell Programming and Scripting 19 05-26-2008 10:18 PM
Parsing a line in Shell Script unishiva Shell Programming and Scripting 3 11-01-2007 04:30 PM
Help in parsing a CSV file with Shell script mihirk Shell Programming and Scripting 10 06-24-2007 11:58 AM
Parsing a file in Shell Script sendhilmani123 Shell Programming and Scripting 4 11-30-2006 02:29 AM
shell script argument parsing rmjoe Shell Programming and Scripting 1 07-28-2005 04:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-11-2007
jjamd64 jjamd64 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
Question shell script parsing with sed

#I'm quite new to scripting and my boss has asked me to solve a simple problem and sadly, I can't figure out how to do it. Any help is appreciated.


#The following is a small shell script and the output that it produces for google.com.

#!/bin/sh
whois $1 | grep "Name Server"
dig +short $1 mx
dig +short mail.$1

[jjamd64@localhost ~]$ ./dn.sh google.com
Name Server: NS1.GOOGLE.COM
Name Server: NS2.GOOGLE.COM
Name Server: NS3.GOOGLE.COM
Name Server: NS4.GOOGLE.COM
10 smtp3.google.com.
10 smtp4.google.com.
10 smtp1.google.com.
10 smtp2.google.com.
googlemail.l.google.com.
66.249.83.83
66.249.83.19

#I need to modify this script so that it deletes the spaces in the beginning of the "name server" line, deletes the numbers and space before the mx records and replaces with a + symbol, and places a - symbol before the IP's. Here is what it should look like:

[jjamd64@localhost ~]$ ./dn.sh google.com
Name Server: NS1.GOOGLE.COM
Name Server: NS2.GOOGLE.COM
Name Server: NS3.GOOGLE.COM
Name Server: NS4.GOOGLE.COM
+smtp3.google.com.
+smtp4.google.com.
+smtp1.google.com.
+smtp2.google.com.
googlemail.l.google.com.
-66.249.83.83
-66.249.83.19

#I would like to use the sed command if possible and any hints would be much appreciated. I'm open to other suggestions as long as it produces the desired output. I really appreciate any direction and tips. THANKS!
  #2 (permalink)  
Old 12-11-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by jjamd64 View Post
I would like to use the sed command if possible
Out of interest, given that you say you can't figure it out, why do you care whether sed is used or not?
  #3 (permalink)  
Old 12-11-2007
jjamd64 jjamd64 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
I would like to get more familiar with sed if possible, but I am open to absolutely any suggestions.
  #4 (permalink)  
Old 12-11-2007
jjamd64 jjamd64 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
OK, I have the first two parts done, the following sed arguments produce the output I need, but I dont know how to insert the - symbol before the IP's. Anyone got any ideas?


#!/bin/sh
whois $1 | grep "Name Server"|sed "s/ //"
dig +short $1 mx|sed "s/[0-9][0-9] /+/"
dig +short mail.$1

[jjamd64@localhost ~]$ ./dn.sh google.com
Name Server: NS1.GOOGLE.COM
Name Server: NS2.GOOGLE.COM
Name Server: NS3.GOOGLE.COM
Name Server: NS4.GOOGLE.COM
+smtp3.google.com.
+smtp4.google.com.
+smtp1.google.com.
+smtp2.google.com.
googlemail.l.google.com.
66.249.83.83
66.249.83.19
  #5 (permalink)  
Old 12-11-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Personally I would pipe it through a read loop

Code:
while read N
do
       case "$N" in
       [0-9]* )
             echo \-"$N"
             ;;
       * )
             echo "$N"
            ;;
       esac
done
But I'm sure some AWK guru can produce some hieroglyphics in a single line to do the job.
  #6 (permalink)  
Old 12-11-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,315
Try this:

Code:
sed 's/^\(..\....\...\...$\)/-\1/'
Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0