The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 06:24 AM
Howto capture data from rs232port andpull data into oracle database-9i automatically boss UNIX for Dummies Questions & Answers 1 09-22-2007 11:35 PM
search and grab data from a huge file ting123 UNIX for Dummies Questions & Answers 1 06-06-2006 06:41 PM
search and replace dynamic data in a shell script csejl Shell Programming and Scripting 8 10-21-2003 07:33 PM
Advanced Search Problems.. Search by User Name Neo Post Here to Contact Site Administrators and Moderators 1 05-18-2003 09:28 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2008
Registered User
 

Join Date: Feb 2008
Posts: 40
how to search data?

Guys, im using grep to search data. But this what i wanted:

$cat file|grep datas
datas1
datas2

but how can i produce like this

$cat file1 |grep ultimatum
ultimatum-1
ultimatum-2
ultimate
ultimate2
to be included in my search,what is the command
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-23-2008
Registered User
 

Join Date: Mar 2008
Posts: 24
hi

try this...
cat filename |grep -i 'ultimat*'

thanks
Reply With Quote
  #3 (permalink)  
Old 03-23-2008
Registered User
 

Join Date: Feb 2008
Posts: 40
any solution that will not use wildcard? because my variable will be hostname in my servers, sor for example my server name is
ultimatum, i also want to get ultimate1, then my other server name is datas
i wanna get data1. So i wont declare ultimat* or data* just command that similar to that. My program is to automate


so it will be:
for i in `hostname`
do
cat $i /etc/hosts
. . . .
Reply With Quote
  #4 (permalink)  
Old 03-23-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The wildcard (and the cat, mind you) are wrong anyway.

egrep allows you to specify patterns with alternates in them. Like this:

Code:
egrep '^ultimat(um-[12]|e2?)$' file
If you have a large list of host names, then perhaps something like this:

Code:
vnix$ fgrep -f - /etc/motd <<HERE
> Ubuntu
> Linux
> GNU
> HERE
Linux indeed 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686
The programs included with the Ubuntu system are free software;
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
vnix$
So the here document contains the "file" of host names on standard input which is being promised by the "-f -" option. Needless to say, this won't work inside a pipeline, but perhaps you can make something of it.

Read up on regular expressions and the differences between grep, egrep, and fgrep.
Reply With Quote
  #5 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Feb 2008
Posts: 40
my ultimatum /etc/hosts contains like this

ultimatum 192.10.5.2 # live
ultimate 192.5.3 #backup
testserver 10.1.1.1

my datas /etc/hosts contains like this

datas 192.2.3.3 #live
data1 192.3.2.1 #backup
testserver 10.1.1.1

and so on..
i already made a script for this remsh, to remotely get the backup.
so by
$hostname
i do now have a variable for the output hostname,
what i wanted a made a universal to get the backup hope you understand what im trying to say.
Reply With Quote
  #6 (permalink)  
Old 03-24-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
I still can't say I understand what your requirements are really. So if you are on datas you want to grep for data1, based on the second line of /etc/hosts on that machine, and similarly other patterns on other machines? Please elaborate.
Reply With Quote
  #7 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Feb 2008
Posts: 40
beacuse i wont suppose to decalare ultimatum or datas which is my histname.
i will just input this comman
$hostname - output of this will be my variable. So no need to declare,just by typing hostname. No need to declare because i have plenty of server and my scri[pt is uniform.

so here it goes,
how can i search i can get my hostname and my backup hostname in /etc/hosts
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, regex, regular expressions, ubuntu

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0