sed on SunOS 5.10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed on SunOS 5.10
# 1  
Old 02-28-2008
sed on SunOS 5.10

Hello all,

I am having some problems using sed on a sunOS 5.10, I am using bash. For some reason the regexp I am trying to build is not working, even though it should.

I am trying to parse some syslog messages and I need to match the first IP address , then replace it with something else. Does anyone have a quick example of a sed line to match and replace an IP address ?

Thanks,
Sylaan
# 2  
Old 02-28-2008
Show us the sed statement you have.
# 3  
Old 02-28-2008
I just tried something simple first, like matching the first number and replacing it with some text:

Code:
server:~$ echo "This is an IP: 172.10.10.3 " | sed  -e "s/([01]?\d\d)/TEST/g"
This is an IP: 172.10.10.3

But it's not really working. What am I doing wrong ? This is the sed I am using:

Code:
server:~$ which sed
/usr/xpg4/bin/sed

# 4  
Old 02-28-2008
Quote:
Originally Posted by sylaan
I just tried something simple first, like matching the first number and replacing it with some text:

Code:
server:~$ echo "This is an IP: 172.10.10.3 " | sed  -e "s/([01]?\d\d)/TEST/g"
This is an IP: 172.10.10.3

[/CODE]
What is ([01]?\d\d) ? That has a Perl resemblance.

Try this one
Code:
sed -e "s/[0-9]\{1,3\}\(\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/TEST\1/g"

[0-9]\{1,3\} is used to match numbers from 1 to 999
\. is used to match a '.'
# 5  
Old 02-28-2008
It seems to work, it replaces the first byte of the IP:
Code:
server:~$ echo "This is an IP: 3.10.10.3" | sed -e "s/[0-9]\{1,3\}\(\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/TEST\1/g"
This is an IP: TEST.10.10.3

How would I go about replacing the whole IP ?
# 6  
Old 02-28-2008
Quote:
Originally Posted by sylaan
It seems to work, it replaces the first byte of the IP:
Code:
server:~$ echo "This is an IP: 3.10.10.3" | sed -e "s/[0-9]\{1,3\}\(\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/TEST\1/g"
This is an IP: TEST.10.10.3

How would I go about replacing the whole IP ?
How do you think that can be done ? Any tries ? I have explained what the regex is.
# 7  
Old 02-28-2008
I think I got it, I need to remove the \1 at the end.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with SUNOS running sed scripts

Hi I probably dont have GNU extended sed in my SUNOS . and its creating lot of problems ex: a simple sed command like this is not working sed '/WORD/ a\ sample text line 1 \ sample text line 1 ' filename sed: command garbled: /WORD/ a I took precaution to have a new line after... (11 Replies)
Discussion started by: vash
11 Replies

2. Shell Programming and Scripting

Issues with sed on SunOS

Why does the below command doesnt work fine on SunOS 5.10 $ cat t | AK| | | | | DS | | | | tAR | | | | | FIL | $ sed -e 's/^ *//g' -e 's/ *$//g' -e 's/ *| */|/g' t |AK|||||DS|||| tAR|||||FIL| ##notice before tAR works fine on Linux OR AIX though ... (8 Replies)
Discussion started by: Shivdatta
8 Replies

3. Solaris

SunOS 5.6

Hi, I called Sun and they said they no longer sell SunOS 5.6. I desperately need a CD-ROM of the install CD to perform maintenance work on a server. Does anyone know where to get one or know someone who can make me a copy? (2 Replies)
Discussion started by: mojoman
2 Replies

4. Solaris

SunOS 5.8 vs 5.10

Hi, I am bulding a path to open files like this \path\values\file.xxx This path is opened in an IE browser window and opens the file/document I am trying to see. I mean it opens a pdf document or it promps you to "save" or "open" the specific file (if it's a .xml, .doc, .html). I was using... (1 Reply)
Discussion started by: hcibl_javok
1 Replies

5. Solaris

New to SunOS...

...and I'm having an issue with memory usage. I got an alert from our sun management console that the box is at 90% memory usage. I need to know what's eating up the memory as this particular box has 16GB of RAM. (3 Replies)
Discussion started by: bbbngowc
3 Replies

6. Shell Programming and Scripting

awk -v in SunOS

Hi folks I have a small problem wherein i have to obtain the data for the last 5 minutes from a logfile. I need to schedule this script in the crontab so that it runs every 5 minutes. A sample of the data is as shown The first field is the hour, second the minute, third field is msg... (3 Replies)
Discussion started by: PradeepRed
3 Replies

7. Solaris

Looking for help with SunOS 5.6

Hey all, I've got my hands on 10 SunOS 5.6 SPARCStation 20 machines and I'm looking to get them up and running. They're all in various states of disrepair but I've got them all to a state where the hardware is working and the machine will at least attempt to boot. I've only used Solaris as a... (1 Reply)
Discussion started by: kevpatts
1 Replies

8. Solaris

SunOS 5.4

Hi, I Hope you can help me with my problem. I need to have an installation CD of this version. Is there any site you can recommend that I can download an image of this OS? Thanks and God Bless!!! (6 Replies)
Discussion started by: mr_balodoy
6 Replies

9. UNIX for Advanced & Expert Users

Migration of binary file from Sunos 5.8 to Sunos 5.9

I have compiled binary file using "cc" on SunOS 5.8 and the same binary file i have copied to SunOS 5.9 and it is giving me core dump error.I want to know whether migration of compiled code from lower version to higer version created this problem. how can i solve this problem.I am pasting the core... (1 Reply)
Discussion started by: Arvind Maurya
1 Replies

10. Shell Programming and Scripting

SunOS 5.8

I am loging into a SunOS 5.8 box for the first time. I do not see a .profile file in the home directory. Also on the command line when I type a backspace to correct my typing I get a ^H character. Where and how can I fix this? Thanks in advance (5 Replies)
Discussion started by: jxh461
5 Replies
Login or Register to Ask a Question