|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help with 2 similar commands with different outputs
NEVERMIND.... "$TIME" did the trick... stupid me. ![]() Hi, I know that this must be something pretty dumb but I cant figure it out myself. I have this: Code:
#!/bin/bash TIME="Time: 20120611" FILE=file.log grep $TIME $FILE And I get the following output: Code:
file.log:Time: 20120611 file.log:Time: 20120611 file.log:Time: 20120611 . . . but when i run Code:
grep "Time: 20120611" file.log I get my expected output: Code:
Time: 20120611 Time: 20120611 Time: 20120611 . . . Why I get 2 different outputs when basically Im using the same command? Thanks in advance Last edited by RedSpyder; 06-13-2012 at 09:36 AM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
I guess (and it is just a guess, since I know next to nothing about how shell works) is that 1. Since the variable $FILE may refer to more than one files, grep is showing you the exact filename which matches content. 2. The variable TIME is not quoted in the grep command. Doesn't it show you a "no file or directory found" message? What is the output of: Code:
TIME="Time: 20120611";FILE=file.log; grep "$TIME" $FILE If it does not show you the file name in output, then my guess is that the part after "Time:" of the TIME variable is being treated as one of the search files and hence the output tells you the name of the file in which the data is found (as is the norm for multiple file grep). |
| The Following User Says Thank You to jawsnnn For This Useful Post: | ||
RedSpyder (06-13-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Yeah the problem is that I didnt used "" around $TIME. Put them and it worked.
Thanks! |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| create outputs from other command outputs | rajsharma | Shell Programming and Scripting | 1 | 07-14-2010 07:43 AM |
| Shell script outputs different results when commands are entered directly on the CL | atilano | UNIX for Dummies Questions & Answers | 3 | 02-01-2009 03:46 PM |
| compare 2 outputs | melanie_pfefer | Shell Programming and Scripting | 1 | 05-21-2008 09:20 AM |
| LotusScript similar to shell commands - need help | bushey1 | Shell Programming and Scripting | 0 | 02-27-2008 09:20 AM |
| Printing outputs using awk. | Krrishv | Shell Programming and Scripting | 4 | 01-09-2007 06:31 AM |
|
|