| | |
Help with grep?
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
0
#2 23 Days Ago
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
3
#3 23 Days Ago
•
•
•
•
If I have two lines of text:
HOOK
HOOK HOOK
what is the syntax to grep just the first line without the second? and the second without the first?
Shell Scripting Syntax (Toggle Plain Text)
grep '^HOOK$' file_name
Shell Scripting Syntax (Toggle Plain Text)
grep -v '^HOOK$' file_name
However, if there were another line containing something that is not
^HOOK$ it will produce a match as well. •
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 3
0
#4 23 Days Ago
Are you wanting to try and grep "HOOK" on a line by itself, or specifically just the first match?
There are all sorts of things that you could actually want to know, although I am not sure which you are wanting. What exactly is it that you are needing to do?
There are all sorts of things that you could actually want to know, although I am not sure which you are wanting. What exactly is it that you are needing to do?
Shell Scripting Syntax (Toggle Plain Text)
# grep a file, return first result and stop grep -m1 "HOOK" file.txt # grep a file, only return result with HOOK on line by itself grep -P "^HOOK$" file.txt # you can also use egrep (or instead of -P use pgrep)
![]() |
Similar Threads
- 'GREP' usage on huge files, any Limitation? (Shell Scripting)
- Program for Grep search (Pascal and Delphi)
- Using Grep (*nix Software)
- derive full name of user and grep search count (Shell Scripting)
- help writing a grep program (C)
Other Threads in the Shell Scripting Forum
- Previous Thread: OMG... simple question driving me nuts
- Next Thread: korn script issue
| Thread Tools | Search this Thread |






