Programming :: Grep Search Between N-m
Oct 5, 2010
How can i use grep (or any other command) to check for lines that begin with N number.
E.g. I want to print out commands (from history), but only from the command number 50 until #200.
This one doesn't work:
Code:
history | grep "^[50-200]"
Should print out something like:
Code:
50 cd ~/Desktop
[Code].....
View 4 Replies
ADVERTISEMENT
Jun 2, 2010
i want to search some key words in some pdf files grep myword ~/test.pdf that command can't work! grep command can't search pdf file??
View 1 Replies
View Related
May 20, 2010
How can I use grep to search for line with either 'res' or 'rep'? i try "grep -e res|rep" or gre -e "rep|rep" but that does not work.
View 3 Replies
View Related
Jan 19, 2010
I am searching for Class declaration on a site with hundreds of PHP files, how can I do this in the current folder and subfolders using GREP?
I tested cding to the folder and then something like
grep -r 'class MyClass' *.php
View 5 Replies
View Related
Jan 13, 2011
I have a mail.log file, of which I want to redirect only the search strings of the sender from=<example.sender@exampledomain.com> and the size size=4537 to a file.
In every case the sender string starts as from=<> and the size string starts as size=
What would be the grep command to redirect only the two search strings to a .txt file?
View 2 Replies
View Related
Feb 16, 2011
I am using ascript for general users to back up usb drives to lto4 tapes.. I wish to ahve some error checking to check IF is there is a tape in the tape drive to check for the tape:
if i do a
sudo mt -f /dev/st0 status
i will get back a
mt: /dev/st0: rmtioctl failed: Input/output error
if there is no tape in the drive or
sudo mt -f /dev/st0 status
[code].....
View 4 Replies
View Related
Sep 17, 2010
I have done a bunch of searches on this but the terms seem to get tangled in the more popular search of "colouring the output of grep / awk". I am trying to find a way to grep/awk through the output of a command to find text of a specific colour. The command's output has a range of colours signifying too many different things to specify using text, with colour being the only form of grouping.
View 5 Replies
View Related
Feb 10, 2010
I need to search for the following pattern with GREP in a text file:
So I tried already:
But none of those works...I think probably because GREP doens't like the special character > in the middle of the serach pattern.
At the end I just need to now if GREP found the pattern in the file or not, so it should give me a 0 or a 1 back, once I check the value of the variable "?" after using the grep command.
View 4 Replies
View Related
Nov 22, 2010
I need to kind of grep within grep. My input file would be something like:
[Code]....
and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:
[Code]....
View 4 Replies
View Related
Jul 10, 2010
I know you can use grep to find keywords in filenames, but is there a variation that can enable you to search the content of the files themselves?
View 9 Replies
View Related
Sep 1, 2011
how to search for those files which contain word "AM_COLLECTION=22". I need to know all the files with this string. ( I know the grep command can do it but either
View 4 Replies
View Related
Mar 26, 2009
I've been trying to identify all files on my cut-down version of Damn Small which contain the text string "User Agent:" in them. Because it's only 120Mb in its entirety, I'm quite happy to have grep search the whole system. I'm using this command, but it just generates errors as you can see:
[root@localhost ~]# grep -R 'User Agent:' /*
grep: /dev/dri/card0: Invalid argument
grep: /dev/fuse: Operation not permitted
[code]....
View 13 Replies
View Related
Feb 19, 2010
I have a three input day,month and year. Currently i am using the following script to take the data.
Any grep advanced technique to avoid for loop?
View 2 Replies
View Related
Oct 1, 2010
somewhere lurking is a file containing the default print resolution, which is not being overwritten by printer settings or cups management. I've asked on the cup forum and nothing successful.
So here's the question:
How can I configure grep to search recursively through all files in a directory, or if need be starting from root to find the pattern "2880" I've looked in the man page for grep and I can't see how to do it, is grep the right tool to use for this ?
View 2 Replies
View Related
Nov 11, 2010
I want to pipe the output of a command into grep as the search TERM, rather than the text to be searched, like this for example
Code:
cat /var/log/auth.log | grep date "&b &d"
so that I only see the lines in auth.log for the current day...but obviously that line doesn't work.... is there a way to do this with grep, or even another command?
View 4 Replies
View Related
Feb 28, 2011
I know grep can search recursively (ie through all subdirectories to the bottom of the directory tree), but is it possible to ask grep to only search say, 3 levels down? That means the current directory, any directories in the current directory, and within any directories within those?
View 1 Replies
View Related
Mar 6, 2010
To search a string pattern in all files in a directory and subdirectories, I am using;
Code:
grep -R "myclass::my-func(" mydirectory/
Now I want grep, to search in only specific file types say *.cc. Please help me. I have read manual of grep, but could not deduce any hint.
Best Regards.
View 7 Replies
View Related
Jan 19, 2010
I need to search a text file for a string of numbers which are different lengths, and always are between number=" and " like:
number="1234567890"
number="22390"
I need to grab those numbers and pipe each one to a line in a file. I've already tried something with awk and that didn't seem to work.
View 10 Replies
View Related
Jun 17, 2010
I use the following command to find under /var some param in my script
grep -R "param" /var/* 2>/dev/null |grep -wq "param"
my problem is that: after grep find the param in file grep continue to search until all searches under /var/* will completed
How to perform stop immediately after grep match the param word
For example when I run the: grep -R "param" /var/* 2>/dev/null |grep -wq "param"
grep find the param after one second.
But grep continue to Search other same param on other files and its take almost 30 seconds
How to stop the grep immediately after param match?
View 1 Replies
View Related
Feb 19, 2011
I'd like to search the entire server by content. (text file) When I try grep -rl "text here", it freezes. How would you do it? And how long does it usually take?
View 4 Replies
View Related
Aug 23, 2010
I am trying to monitor how long an ldap search takes and maybe notify or something that a search takes longer than say 10 seconds.
Code:
tail -n 1000 /var/log/ldap.log
for SRCH in $( cat monitorldap.log |grep 'SRCH'); do
echo search string is
echo $SRCH
[Code]....
ok, so to start off with it doesn't appear to get the whole line, just a piece "Aug". How can I get the whole line into a variable so I can then cut it up into the pieces I need?
View 4 Replies
View Related
Dec 28, 2010
I'm using Zabbix on which I can use give bash command to the agent.This 1-liner will give me all the interfaces with their IPv4 addresses.I have a 2nd expression which returns a checksum so I can detect a difference whenever someone deletes/adds/changes an ipv4 interface.This is the output on my Ubuntu-server:
Code:
~# ifconfig | grep -B1 ' inet ' | grep -oE '(^[a-z0-9:]*|addr:[0-9]+.[0-9]+.[0-9]+.[0-9]+)'
eth0
[code]....
View 8 Replies
View Related
Aug 6, 2010
1) I need to search a field value to check for exact 0. If the number is 0, it should throw error.
The line to be searched looks like as below. "Output Rows [1], Affected Rows [1], Applied Rows [1], Rejected Rows [0]"
Here I have to search whether the affected rows is 0. But the code below picks up other values also (lie 10, 20.. etc). How do we write to get an exact match for 0? Code: affected=`echo ${line} | cut -f6 -d" " `
affectedcount='echo ${affected} |grep 0 ` 2) Also, I need to check whether the rejected rows > 0
Code: rejected=`echo ${line} | cut -f12 -d" " `
rejectedcount='echo {rejected} |grep [1-9]`
3)Can we combine these two statements in a better way to get the desired results?
View 2 Replies
View Related
Mar 15, 2011
I have a file:
979798707
787862348
766428634
I want to see if all the records in the file are present in the contents of the files of a particular directory.
Basically I want to say if grep doesn't return anything, then report.
For example in /tmp dir I have 4 files and flast 2 values (787862348 and 766428634) are present in the files of /tmp dir, but first one (979798707) is not. I want to echo that in a reporting file.
something like:
while read line
do
# if ! grep -rl $line /tmp
echo $line >> are_not_present
done < "myFile"
How do I achieve " if ! grep -rl $line /tmp"? That is, if the line is found by grep, then grep will print the output, but if grep does'nt find it, it will print nothing. How can I check if grep didn't find it (i.e. printed nothing)?
View 2 Replies
View Related
Mar 23, 2011
Can you find an alternative for Code: wc -l using grep?
View 1 Replies
View Related
Jun 1, 2011
I'm just starting out with bash scripting (yesterday, really). I want to add a file to each user's home directory, pretty simple really, and send it out via our Apple Remote Desktop system to our Macs. Here is my script: Code: #!/bin/bash
for i in $(ls -d /Users/*)
doif [ -e $i/.tcshrc ]
thenecho "$i/.tcshrc exists!"elseecho "$i/.tcshrc does not exist"
[code]....
View 6 Replies
View Related
Dec 3, 2010
i have a sample that looks like this:
Code:
[schneidz@hyper temp]$ wget -q --output-document=- http://world.needforspeed.com/SpeedAPI/ws/game/nfs-w/leaderboards/events
[code]....
View 2 Replies
View Related
Feb 9, 2010
I am using Sun 5.9.
I am putting the value "Feb 10" in variable 'c' here.
Code:
-bash-3.00$ c=`date | awk '{print $2 " " $3}'`
-bash-3.00$ echo $c
Feb 10
But when I am grep-ing value of 'c', I am getting this error.
Code:
-bash-3.00$ ls -lrth | grep $c
grep: can't open 10
This is because there is a space between "Feb" and "10".
View 5 Replies
View Related
Dec 30, 2010
I want grep multiple files:
let abc.1.abc.2,abc.3,abc.4
I use grep <pattern> abc.* to read the files. But here grep read files in the order of 1,2,3,4 . I want to to grep the files in reverse order like 1st the abc.4 file will be read and abc.1 file will be last.
Is this possible ?
View 3 Replies
View Related
Aug 10, 2010
I am interested in using the grep method in the shell of my CentOS machine to obtain patterns from a file and use them to search through another file and highlight the patterns found. For example:
pattern file:
one
two
three
test file:
AAAAAAAAAAAAAAAAAAAAAoneAAAAAAAAAAAAAAAAthreeAAAAAAAAAAAA
View 8 Replies
View Related