Need to only remove parenthesis and : leave the rest


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to only remove parenthesis and : leave the rest
# 1  
Old 08-30-2005
Need to only remove parenthesis and : leave the rest

Hi all,

I'm stuck on this last part...am running a simple script under AIX to extract NetView host IP addresses. The line below returns the IP address in parenthesis with a trailing colon, i.e.

ping -c 1 $name |grep \( | awk '{ print $3 }' --------> returns

(a.b.c.d):

How can I only remove the parens and colon while leaving the IP address?

Thanks!
# 2  
Old 08-30-2005
To get the IP address , I used the following:

Code:
export HOST=`uname -n`
export ip=`cat /etc/hosts | grep -v ^# | grep -v 127.0.0.1 | grep -w ${HOST} | awk '{print $1}'`

More purified ....

Nir
# 3  
Old 08-30-2005
Quote:
Originally Posted by livinthedream
Hi all,

I'm stuck on this last part...am running a simple script under AIX to extract NetView host IP addresses. The line below returns the IP address in parenthesis with a trailing colon, i.e.

ping -c 1 $name |grep \( | awk '{ print $3 }' --------> returns

(a.b.c.d):

How can I only remove the parens and colon while leaving the IP address?

Thanks!
what does the 'ping -c 1 $name' return AND what would you like to get back?

I don't think there's a need to 'grep' feeding 'awk' and [maybe] feeding another awk/sed.

Last edited by vgersh99; 08-30-2005 at 12:33 PM..
# 4  
Old 08-30-2005
Quote:
Originally Posted by nir_s
To get the IP address , I used the following:

Code:
export HOST=`uname -n`
export ip=`cat /etc/hosts | grep -v ^# | grep -v 127.0.0.1 | grep -w ${HOST} | awk '{print $1}'`

More purified ....

Nir
wow... this should be UUOC and UUOG^3 [among others].....
Code:
ip=$( nawk -v host="$(uname-n)" '!/^#/ && !/^127.0.0.1/ && $2 == host {print $1}' /etc/hosts )

# 5  
Old 08-30-2005
Quote:
Originally Posted by vgersh99
wow... this should be UUOC and UUOG^3 [among others].....
Code:
ip=$( nawk -v host="$(uname-n)" '!/^#/ && !/^127.0.0.1/ && $2 == host {print $1}' /etc/hosts )

Wow, quick responses. I probably should have posted the entire source. As you can tell I'm not a coder ;-) What I need to do is run a command that dumps out the list of hostnames from a database; I then feed them through a loop that pings the hostname. I'm trying to scrape the IP address out of the result and ultimately produce a file that has hostname <tab> IP address.

HOSTNAME=`ovtopodump -rl |grep HOSTNAME | cut -f2 -d\ `

for name in $HOSTNAME
do
ping -c 1 $name |grep \( | awk '{ print $3 }'
done


Right now I'm getting the IP address but need to clean out the surrounding crud! And I do realize grep and awk aren't needed on the same line. I do this so infrequently and the scripts are usually run once or maybe run daily.
# 6  
Old 08-30-2005
once again, could you post the output of 'ping -c 1 name' AND describe what part of it you need.

YMMV:
Code:
echo '64 bytes from skywalker (192.168.64.205): icmp_seq=0. time=0. ms' | nawk -F'[()]' '{print $2}'


Last edited by vgersh99; 08-30-2005 at 03:18 PM..
# 7  
Old 08-30-2005
Quote:
Originally Posted by vgersh99
once again, could you post the output of 'ping -c 1 name' AND describe what part of it you need.

YMMV:
Code:
echo '64 bytes from skywalker (192.168.64.205): icmp_seq=0. time=0. ms' | nawk -F'[()]' '{print $2}'

Sorry about that--output is below. I need the IP address just like you have in your example above:

PING server1.us.xxxxx.com: (10.26.10.31): 56 data bytes
64 bytes from 10.26.10.31: icmp_seq=0 ttl=128 time=0 ms

----server1.us.xxxxx.com PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0/0/0 ms


Grepping for the first paren and awking gets me the IP address, just gotta clean it up. Appreciate the help folks!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove parenthesis and run awk calculation

The awk below works fine if I manually remove the () from file1. However, when I try to use tr to remove the () and then | into awk to run the calculation no result is obtained. Is there a way to tell the awk to ignore the () in fiile1 if they are there or do I need to remove them first? Thank... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

Renaming files to remove everything before one parenthesis

Hi, I have files in a folder that I would like all renamed without the preceding number and parenthesis. For example, I have files of the name 08) Great Good Fine Ok - Not Going Home 09) Roosevelt - Small Hours 10) RAC - I Should've Guessed Feat. SPEAK and I would like them all to be... (4 Replies)
Discussion started by: jyu429
4 Replies

3. Shell Programming and Scripting

Remove the last 15 characters of a filename with respect to leave file extension

how can i remove numbers of characters from the last name of file with respect to not remove the files extension example VFX_Official_Trailer_(HD)__Shhh__-_by_Freddy_Chavez_Olmos_&_Shervin_Shoghian-.mp4 i want to rename this to VFX-Official-Trailer-(HD)-Shhh... (13 Replies)
Discussion started by: ateya
13 Replies

4. Shell Programming and Scripting

Remove last occurrence of character (_) and rest of the string in UNIX (sed)

Hi I need help on this ..!! Input : xx_abc_regA xx_def_regB xx_qwe_regC Now i required the output as the below abc def qwe Need to remove last occurrence of character (_) and rest of the string in Unix (sed). Thanks in Advance ..!!! -Nallachand (3 Replies)
Discussion started by: Nallachand
3 Replies

5. Shell Programming and Scripting

awk delete/remove rest of line on multiple search pattern

Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum: infile: 64_1535: Delm. = 86 var, aaga 64_1535: Fran. = 57 ex. ccc 64_1639: Feb. = 26 (link). def 64_1817: mar. = 3/4. drz ... (7 Replies)
Discussion started by: sdf
7 Replies

6. Shell Programming and Scripting

Cleanup between parenthesis

Hi, I am trying to clean up data between parenthesis () in a file. See example below.... Input File : (New York) Chicago (London) New York (Chicago) London New York Chicago (London) (New York) (Chicago) (London) New York (Chicago) ... (3 Replies)
Discussion started by: msalam65
3 Replies

7. Programming

how to check parenthesis in MSVC++

how do i turn on the option to check for opening and closing parenthesis in Microsoft VC++? I remember there is a setting somewhere in the options in the MS VC++ environment but not sure.. thanks (4 Replies)
Discussion started by: npatwardhan
4 Replies

8. Shell Programming and Scripting

Remove parenthesis character (Perl)

Hello, i'm unable to remove the parenthesis character. With $parsed_AsciiName =~ s/\(//; the string is the same And with $parsed_AsciiName =~ s/(//; i retrieve "Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE" Any ideas, please? thank you in advanced. (4 Replies)
Discussion started by: aristegui
4 Replies

9. Shell Programming and Scripting

remove a colon and number and leaving the rest

just have a file 1:2333 2:-09393 ]3:45453 4:-09999 5:-09933 6:93939 question is to get output by removing colons as well as number before each colon (in bold) 2333 -09393 45453 -09999 09933 93939 (5 Replies)
Discussion started by: cdfd123
5 Replies
Login or Register to Ask a Question