![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 . . . . |
|
|||
|
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 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$ Read up on regular expressions and the differences between grep, egrep, and fgrep. |
|
|||
|
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. |
|
|||
|
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.
|
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
| Tags |
| linux, regex, regular expressions, ubuntu |
| Thread Tools | |
| Display Modes | |
|
|