sed on SunOS 5.10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed on SunOS 5.10
# 8  
Old 02-28-2008
Quote:
Originally Posted by sylaan
I think I got it, I need to remove the \1 at the end.
You are on your way. But what is inside \1 ? How did I collect the pattern inside \1 ?
# 9  
Old 02-28-2008
Quote:
Originally Posted by vino
You are on your way. But what is inside \1 ? How did I collect the pattern inside \1 ?
I thought that is what's inside the (, ) but that does not encompasses the whole pattern.
# 10  
Old 02-28-2008
Ok, I just moved the first \( and now \1 is the whole pattern, I can replace it and it works Smilie Thanks for your help so far.

Now I need to do something else. I actually need to replace the IP with a hostname. I have a small script that does this but I am not sure how to pass the \1 to my script, inside the sed statement.

Normally the script does this:
Code:
server:~$ res 10.1.1.3
host1.domain.com

The res script is just a simple grep script:

Code:
server:~$ cat bin/res
#!/usr/bin/bash
grep -w $1 /etc/hosts | cut -f2

But when I try to integrate it into the sed line, I get this:

Code:
server:~$ echo "This is an IP: 10.10.2.10" | sed -e "s/\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/`res "\1" `/g"
grep: RE error in \<\1\>: number in \[0-9] invalid
This is an IP:

The grep inside "res" does not like the \1, which I kinda understand. Thing is, if I do a simple echo "\1" instead of the res "\1" then it works, the \1 is replaced with the actual IP from the sed statement.

Any ideas ?

Thanks,
Sylaan
# 11  
Old 02-28-2008
What about
Code:
NAME=$(res 10.1.1.3)
echo "This is an IP: 10.10.2.10" | sed -e "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/$NAME/g"

# 12  
Old 02-28-2008
That works but I kinda need to use the \1, the IP address that I matched. The lines I am going to parse will be syslog entries, which contain IP addresses. I just need to tail the syslog, pipe it through the sed statement and replace the IP address with its equivalent hostname (which I get via the small res script).
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