Cannot get results from grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot get results from grep command
# 1  
Old 12-07-2015
Tools Cannot get results from grep command

Hi,

i have a file hello.log which as several line that look like the below

Code:
2015-12-07      09:46:56       0:339   120.111.12.12   POST    /helloWorld
2015-12-07      09:46:57       0:439   122.111.12.12   POST    /helloWorld
....

when i grep expecting to see results like the below.

Code:
grep '2015-12-07      09:4' hello.log

I do not see any results when i was expecting to see both the above lines in the output.

Can you tell me if my grep is ignoring the white spaces between the two strings and what should be done to fix this ?
# 2  
Old 12-07-2015
Try:-
Code:
egrep "2015-12-07[ ]+09:4"

# 3  
Old 12-07-2015
It works exactly as expected and prints the two lines as they are matching... Did you try with wildcards or sequences (e.g. " *")?
# 4  
Old 12-07-2015
Quote:
Originally Posted by mohtashims
[...]
Can you tell me if my grep is ignoring the white spaces between the two strings and what should be done to fix this ?
grep is not ignoring the white spaces, most likely the white spaces are not matching. i.e. it could be that white spaces are tabs or mix of tab and single spaces and you are using perhaps just spaces or any of those combinations.
# 5  
Old 12-07-2015
Quote:
Originally Posted by RudiC
It works exactly as expected and prints the two lines as they are matching... Did you try with wildcards or sequences (e.g. " *")?
It does not print output anything ... that the problem ... i was expecting both the lines to be printed.

---------- Post updated at 12:32 PM ---------- Previous update was at 12:31 PM ----------

Quote:
Originally Posted by Aia
grep is not ignoring the white spaces, most likely the white spaces are not matching. i.e. it could be that white spaces are tabs or mix of tab and single spaces and you are using perhaps just spaces or any of those combinations.
This is what i think is happening ... but how will i be able to understand and grep if it has tabs and other white spaces !!
# 6  
Old 12-07-2015
Try
Code:
grep '2015-12-07[[:space:]]*09:4' file
2015-12-07      09:46:56       0:339   120.111.12.12   POST    /helloWorld
2015-12-07      09:46:57       0:439   122.111.12.12   POST    /helloWorld

This User Gave Thanks to RudiC For This Post:
# 7  
Old 12-07-2015
Quote:
Originally Posted by Yoda
Try:-
Code:
egrep "2015-12-07[ ]+09:4"

Does not work ... Not results Found !!

I think it may have tabs aur other whitespace keys .... not sure how can i confirm and get this to work.

---------- Post updated at 12:38 PM ---------- Previous update was at 12:35 PM ----------

Quote:
Originally Posted by RudiC
Try
Code:
grep '2015-12-07[[:space:]]*09:4' file
2015-12-07      09:46:56       0:339   120.111.12.12   POST    /helloWorld
2015-12-07      09:46:57       0:439   122.111.12.12   POST    /helloWorld

Works !! Solved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command to show the number of results

Hi I wanted to know if there is an option in grep command to show the number of results (not the number of lines of findings). Thanks (14 Replies)
Discussion started by: abdossamad2003
14 Replies

2. Shell Programming and Scripting

How to analyse results of grep

Hi all, I'm working with a peice of software that runs on Linux that allows planning trips in cars through maps. This software has different variations depending on the type of car, e.g. BMW, Audi, Hyundai, etc... Each variation has a dependency on common external components that are not... (1 Reply)
Discussion started by: emoshaya
1 Replies

3. UNIX for Dummies Questions & Answers

How to do ls -l on results of grep and find?

Hi, Am running the command below to search for files that contains a certain string. grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active" How do I get it to do a ls -l on the list of files? I tried doing ls -l `grep -il "shutdown" `find . -type f -mtime -1... (5 Replies)
Discussion started by: newbie_01
5 Replies

4. Shell Programming and Scripting

Grep no results

Hello guys, I have been looking around but can't find the answer to my problem: If the grep command displays no results, print "no results have been found" and increment x. But if the grep command find something, do nothing. if echo "no results have been found $x" x=`expr $x + 1 `... (3 Replies)
Discussion started by: Benou
3 Replies

5. UNIX for Dummies Questions & Answers

Acting on results from a grep command

Hi, I am currently reading a tar file and searching for a particular word using grep e.g. Plane. At the moment, if a sentence is found with the word "Plane" the sentence itself is piped to another file. Here is the code i am using; for jar in 'cat jar_file.tar'; do tar -tvf... (3 Replies)
Discussion started by: crunchie
3 Replies

6. UNIX for Dummies Questions & Answers

Pipe results of Grep Command to LS Comand

I'm using the command grep -l XYZ to get a list of files containing the string XYZ. Then I using the comand ls -l ABC to get the create date timestamp of the each file. I've tried combining the comands using the pipe command, grep -l XYZ | ls -l, but its not working. What am I doing wrong? (3 Replies)
Discussion started by: jhtate
3 Replies

7. UNIX for Dummies Questions & Answers

My ps -ef|grep command results are chopped off

On our one HP-UX 11i box, we have some very long paths defined. When I want to check on our user processes running, the resulting paths are chopped off. /xyz/abc/123/......./server/b is really a process running in the ..../server/bin directory. Is this a terminal problem or buffer length... (1 Reply)
Discussion started by: bsp18974
1 Replies

8. UNIX for Dummies Questions & Answers

List grep results

Hi I need to search for matching strings in a database and I want to print out all files that matches in "detail", which means that I want the output to contain datum of last saving. I only get the grep function tp print the actual file names which is not enough since the database is to large... (14 Replies)
Discussion started by: slire
14 Replies

9. Shell Programming and Scripting

How to refine results of grep -p

I need help to further reduce the output shown below. I want to be able to only return the paragraph where the 'Database alias' is exactly equal to DBIHP. I do not want the other paragraphs being shown below. $ echo $dbalias DBIHP $ db2 list db directory|grep -p 'Database alias ... (2 Replies)
Discussion started by: priceb
2 Replies

10. Shell Programming and Scripting

diffrent results between command line and scripted grep

When I type a command at the command line it supplies one result and the exact same command in a script egrep '^01|^02|^03|^04' file > fileout count = 29353 same count in the script yields a count of 23492 is there any reason this could be happening. (1 Reply)
Discussion started by: r1500
1 Replies
Login or Register to Ask a Question