Need some help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need some help
# 1  
Old 07-02-2008
Need some help

Hello guyz

Need some help with this script

script.sh
-----------------------
echo "--------Starting------" > 1.txt

grep "Server " jct.txt >>1.txt
grep "Hostname: " jct.txt >> 1.txt
grep "Port: " jct.txt >> 1.txt



mv 1.txt data.txt
echo "--------Ending----" >> data.txt

------------------------

jct.txt
------------------------
Server 1:
Server State: running
Hostname: 14.14.14.14
Port: 3060
ID:34349
Path:/etc/bin
Server 2:
Server State: not running
Hostname: 14.15.14.15
Port: 6060
ID:34349
Path:/etc/bin
Server 3:
Server State: not running
Hostname: 14.15.14.13
Port: 6160
ID:34349
Path:/etc/bin
-------------------------

I am using script.sh to reterive Hostname and port.When using this script.sh iam getting result as

Server 1:
Server State: running

Server 2:
Server State: not running

Server 3:
Server State: not running
Hostname: 14.14.14.14
Hostname: 14.15.14.15
Hostname: 14.15.14.13
Port: 3060
Port: 6060
Port: 6160

-----------------------

But I need server wise
Ex:
Server 1:
Server State: running
Hostname: 14.14.14.14
Port: 3060

Server 2:
Server State: not running
Hostname: 14.15.14.15
Port: 6060

Server 3:
Server State: not running
Hostname: 14.15.14.13
Port: 6160



I hope you guys understood my problem.Any suggestions!!!

THANKS guys
# 2  
Old 07-02-2008
Code:
cat jct.txt | grep -v 'ID' | grep -v 'Path'

# 3  
Old 07-03-2008
Thanks pal..it is working..
# 4  
Old 07-03-2008
Or more succinctly:

Code:
egrep -v 'ID|Path' jct.txt

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question