Programming :: Input File - Grep Within Grep
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
ADVERTISEMENT
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
May 3, 2010
I want to know that is there any method to grep a particular data from a file without using the "cat --- | grep ' ' " command....I need to use a system call for this functionality.
View 1 Replies
View Related
Oct 27, 2010
I want to write some code to search for a specific string in a text file, but without using grep command.
View 5 Replies
View Related
Jul 16, 2011
I am using File::Find to go through a very large tree. I am looking for all xml files and open only those that contain a tag <Updated>. I then want to capture the contents of two tags <Old> and <New>.
My problem is, after I open the file and do the first grep for <Updated> (which does work), I am unable to grep again unless I close the file and open it.
I did something like this:
Quote:
find(&check, $dir);
sub check {
if ($_ =~ /.xml/){
open(FILE,"$_");
if (grep{/Updated/} <FILE>){ # <-- works
[Code]....
View 6 Replies
View Related
Apr 2, 2010
What I'm trying to do is grep [mysqld] from inside my.cnf and then add lines inside the file should they not be there. how do i do that?
View 3 Replies
View Related
Jul 13, 2010
On one of my servers, it appears that a bunch of html files got the following code added to it...Quote:[URL]I was going to try to remove this line using grep & sed... as sample
grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g'I can get the grep portion to work...
Code:
grep "<script src='http://b.rtbn2.cn/E/J.JS'[>][<]/script[>]" *
But not the sed
View 1 Replies
View Related
Mar 4, 2010
Suppose i have a file(1.txt) separated by TAB delimiter in a line
1 B AB 2
2 C AB 2
if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??
View 5 Replies
View Related
May 1, 2011
My script.
This is may script:
Code:
Problem: Output file doest not exclude the values in grep -av
View 3 Replies
View Related
Nov 13, 2010
I have a huge binary log file. There are lets say 4 id's that I want to find in a log file. I know that those 4 id's will be present in the log file and I also know in what order they will be present. I want to find 1st id from the log then 2nd id and then third id and so on..
Simple/inefficient solution is: Loop through the id's and then grep in the log file. Problem with this solution is for each id grep will search from the beginning of the file.
Better/efficient solution would be: Sine I know the order in which id's will be present in the log file. Loop through id's, grep 1st id and then move on to grep 2nd id and so on...this way I can grep all id's in one pass. Is this solution possible ?
I have 500000 + values to find in log files and I have to find efficient solution for it.
View 2 Replies
View Related
May 28, 2010
I'm trying to math all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp. I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working as I espected:
grep -E '^[^(/*)(//)].*[^a-zA-Z]ABCZ[]*[*(<:;,{& ]'
^[^(/*)(//)] don't math comments in the begging of the line ( // or /* )
.* followed by any character
[code]....
Well, I can get patterns like this:
class Test: public ABCZ{
class Test: public ABCZ {
class Test : public ABCZ<T>
[code]....
View 4 Replies
View Related
Jul 1, 2010
I need a loop that pulls out the user name into a variable and then pulls out the LastUpdate field into another variable so I can then perform a comparison against the last update field. Requirements are AIX tools including AWK, SED and Perl I am writing a script to check AIX users password expiration dates and if they are within the alerting period (ie. 7 days etc) it will email the user. I will release the full script into the public domain once completed. The text file I want to parse is formatted like:
Code:
colettel:
password = XSON0m4SdIQDw
lastupdate = 1260829398
andrewwa:
[code].....
View 4 Replies
View Related
Aug 13, 2010
I am trying to compare a list of patterns from one file and grep them against another file and print out only the unique patterns. Unfortunately these files are so large that they have yet to run to completion. Here's the command that I used:
Code: grep -L -f file_one.txt file_two.txt > output.output Here's some example data:
Code:
>FQ4HLCS01BMR4N
>FQ4HLCS01BZNV6
>FQ4HLCS01B40PB
>FQ4HLCS01BT43K
>FQ4HLCS01CB736
>FQ4HLCS01BU3UM
>FQ4HLCS01BBIFQ
how to increase efficiency or use another command?
View 14 Replies
View Related
Feb 25, 2010
To start, I'm writing a script to check a file's date via FTP. Here's the portion that I'm having problems with:
Code:
function checkRemote
{
[code]...
View 7 Replies
View Related
Jul 6, 2010
how I can do the following in a bash script?
1) Load all *.log files into an array variable
2) Iterate through the array, and do a "grep" on each of the file to see if it contains a "word".
View 8 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
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
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
Apr 7, 2009
I am trying to use a shell script to find a string in a file and do something when found. code...
What should happen is pppd will start in a different process and stream it's output to pppdout. pppdout should be created in the current folder. Then the script should periodically check the pppdout file for the string Script (which eventually will appear, some seconds later) and when found exit the script. Ultimately the script will do something useful when the text is found. However, the output from the program is a repeating: 'scriptname.sh: 12: FOUND: not found'
Where scriptname.sh would be the name of your script and 12 refers to the line with 'done'.
Why does grep not find the text, or at least why deos my script not check the grep output correctly?
View 10 Replies
View Related
Apr 26, 2010
Would like to know how to cat the below output.
Code:
grep userlist_file /etc/vsftpd/vsftpd.conf | cut -c15-
Below which is the output for above command.
[code]...
View 6 Replies
View Related
Apr 8, 2011
So For example I run this command:
Code:
But want to gerp / cut it in such a way that it only displays
Code:
Now the thing is that these 3 lines are not static.. there can be N number of lines there.. the only thing is that I want the command / output NOT to display the first line but the rest of the n lines ..
View 9 Replies
View Related
Feb 3, 2010
I have a file which contains a line like this:SERVER=10.205.110.19 How can I cut out the IP and assign it to a variable?
View 4 Replies
View Related
May 10, 2010
I'm trying to write a bash script and I'm having trouble with it.I have a list of DNS entires from a file called zoneExport.txt.Than I want to parse a log file to see if that DNS entry has been queried for. So I'm running a grep command and trying to save it into a variable. What I'm looking for is a variable ($varGrepQ) that has the number of matches for the grep query. I will then run this through an if statement and do some things from there..
But my problem right now is with this grep query. It keeps outputting '0' even when I know there are records in that file and when I run the same query on the command line I get the actual count. My thought is that the $record variable is not passing right.
View 4 Replies
View Related