Help with simple grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with simple grep command
# 8  
Old 10-02-2010
Quote:
Originally Posted by puttster
...I think my problem is happening because my line is so long that its only showing the first one, ...
Why does the length of the line matter ? Despite the length of the line, grep should display all lines that match the pattern.

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 9  
Old 10-02-2010
Quote:
Originally Posted by durden_tyler
Why does the length of the line matter ? Despite the length of the line, grep should display all lines that match the pattern.

tyler_durden
I am very new to unix shell... I'm trying to teach myself this stuff so that it will be useful in my future in my computer life Smilie It is starting to get very frustrating so far. I mainly just have a grasp on sed and thats basically it.
# 10  
Old 10-02-2010
Quote:
Originally Posted by puttster
...
--- It seems to me that within my code, It only prints the last line of the file that contains what ever I am grepping, any idea? it counts a certain number but displays the LAST line that it counts!
Just a hunch, but check if there are any funky characters in your data file.

Code:
od -bc your_file

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 11  
Old 10-02-2010
Quote:
Originally Posted by durden_tyler
Just a hunch, but check if there are any funky characters in your data file.

Code:
od -bc your_file

tyler_durden
funky characters meaning ] $ #? because if so then YES there are :P

however I used sed to get rid of some of them, but not all of them since that is not what i'm worried about at this moment!
... or can it have an effect on the grep?
# 12  
Old 10-02-2010
Paste the output of the "od -bc" command over here.

tyler_durden
# 13  
Old 10-02-2010
Quote:
Originally Posted by durden_tyler
Paste the output of the "od -bc" command over here.

tyler_durden
ill post a sample :P because its still going... 5mb file Smilie

---------- Post updated at 01:36 AM ---------- Previous update was at 01:28 AM ----------

Image


Do I have to sed out all of the #*&^%$ characters in my text that are scattered in the file in order for grep to work correctly?
# 14  
Old 10-02-2010
Your data file is messed up. Run the following command and then run grep.

Code:
dos2unix your_file your_file

If you do not have "dos2unix" in your system, try "dos2ux".
Otherwise, you could try this -

Code:
perl -pi.bak -e 's/\r//g' your_file

Back up your file before you run any of the commands above.

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Simple grep question

I hope someone can help me. I have a folder e.g. /opt/application Under that are many sub folders e.g. Folder1 Folder2 Folder3 Folder4 Folder5 Folder6 etc In some of these fodlers (not all of them) is a file called errors.log I need to run a grep that will start at... (3 Replies)
Discussion started by: gunnahafta
3 Replies

2. Shell Programming and Scripting

Help with simple RegEx on grep

Hello, I am trying to grep my log files for ORA errors, except ORA-00001. I have tried: grep 'ORA*!(-00001)' *.log but it is not working. Any help will be much appreciated. Thank you. (5 Replies)
Discussion started by: drbiloukos
5 Replies

3. Shell Programming and Scripting

Simple grep script

I'm trying to write a simple script to identify every user who tried to “sudo” on the system. I have the first portion down to grep the log file grep “sudo” /var/log/secure. What I want to do is have the script identify the person just one time not every instance the user tried... (4 Replies)
Discussion started by: bouncer
4 Replies

4. UNIX for Dummies Questions & Answers

Simple grep question

This should be so easy... I want to find all the apps in /Applications that start with the lower case i (e.g. iTunes.app, iSync.app, iCal.app) They should all have the .app extension. I've tried: ls /Applications |grep -o i*.app ls /Applications/i*.app Anyhow, I just want to see what apps... (2 Replies)
Discussion started by: glev2005
2 Replies

5. Shell Programming and Scripting

simple grep is not working for me

Hi, On the log Netscape log, I need to grep for 500 error. I am doing that but I also get 1500 in that same log. cat access |grep "500" Results: "GET /css/RBR.css HTTP/1.1" 200 15000 304 - - - 399 639 523 164 0 This not what I need... Please advice. (4 Replies)
Discussion started by: samnyc
4 Replies

6. Shell Programming and Scripting

Simple grep Question

I tried searching for answers but didn't find any. When I grep a file results read 4.2.2.2 4.4.4.2 4.5.6.7 But I just want to select each result individually. For Example I want to be able to say variable1="first grep result" variable2="second grep result" variable3="third grep... (8 Replies)
Discussion started by: elbombillo
8 Replies

7. UNIX for Dummies Questions & Answers

Simple newbie grep question

How come grep testfile1 won't find anything in testfile1 (even though the characters sd are there in great quantity), but grep '' testfile1 will find plenty? Do the single quotes prevent the shell from interpreting the testfile1 is interpreted as: grep *test whether or not characters sd exist*... (5 Replies)
Discussion started by: doubleminus
5 Replies

8. UNIX for Dummies Questions & Answers

Simple grep - Not sure it makes sense!

I have 3 files in directory mydir named as follows, I run the sequence of commands shown below and I have questions at the result. File names are: ABC_GP0 ABC_GP0.ctl ABC_GPX Commands and results: $ ls /mydir/ | grep * <-- (q1) I get nothing - OK $ ls /mydir/ | grep... (5 Replies)
Discussion started by: GNMIKE
5 Replies

9. UNIX for Dummies Questions & Answers

simple grep question

I have seen this used several times but not really sure of what it actually does. I am confused with the second grep as the argument to the first. some commands | grep -v grep | some other commands Can anyone provide an explanation? Thanks, (5 Replies)
Discussion started by: google
5 Replies

10. UNIX for Dummies Questions & Answers

Simple grep questions

Hi all, My boss wants me to find out how often e-m users are accessing their account:confused:. The mail server keeps log of all logins. I want to use grep the 'usernames', but it should come out the moment it first encounters the username in the log. Can I do that? I want to avoid 10+ greps... (2 Replies)
Discussion started by: nitin
2 Replies
Login or Register to Ask a Question