Programming :: Grep Until Certain Character Or Pattern Appears
Jun 25, 2010
I have the following command that greps "/etc/cron.allow" and displays the following 9 lines of $file grep -A 9 "/etc/cron.allow" $file On the other hand I would like to grep a file for a certain text display the next couple of lines and stop when i hit a specified word or blank or pattern.Basically I would like my grep to end when the shell hits a blank, certain key word or pattern specified in command.
View 7 Replies
ADVERTISEMENT
Apr 29, 2010
I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:
- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email
View 3 Replies
View Related
Dec 9, 2010
I need to grep a pattern which can be present in one line or could be split in 2 lines.Normal grep wont work in this case. Can anyone please help on this?There are 100's of files in which i need to search for this pattern so time is also a constrain.
View 5 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
Nov 19, 2008
I'm having a bit of trouble with a regular expression I'm trying to write and I'm not sure if it's something Tcl specific or my lack of regexp understanding.
[Code]...
I get a number of strings passed to a proc in the format 3|x where x is a number, either 0 or within the range 5-12. My understanding is that that regexp will match the literal '3' followed by a '|', the escapes the special meaning of |, and then 0 or, because of |, a number within the range 5-12. However I'm getting the error 'couldn't compile regular expression pattern: invalid character range'.
View 3 Replies
View Related
Feb 24, 2010
I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?
View 1 Replies
View Related
Jul 7, 2011
How can I use grep -Ev "pattern" not only to delete the matching "pattern" but to edit and save the file permanently as well
View 2 Replies
View Related
Mar 5, 2011
Want to grep pattern of root dir. (/). Staying in current directory. But I don't want to use the below code:
cd /
grep m *
View 3 Replies
View Related
Sep 25, 2010
I would like to write a newline delimeted rules file using PCREs for use with the grep command. Grep has the option -f to obtain the search pattern from a file, and option -P to search using PCREs. However, these two options do not work together. The -f option only seems to work with fixed string rules.A friend previously helped me get around this limitation somehow, but I can't remember how he did it. I also would like the ability to add comments at the end of each rule in the file.
View 11 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
Aug 15, 2010
I want to grep a a file for each '#' character that starts a line, the thing is the file is utf-8 and it starts with some some characters 'ef bb bf' is there a way to have grep to work with utf-8 files ?
[Code]....
View 2 Replies
View Related
Jul 7, 2011
I am filtering some output from gcc with grep. But if the output contains the accent character (`) I run into a problem.Then I have to press ctrl/c to get back to a prompt.
(1) Can someone tell me what is going on? I suspect that it is trying to match up the accent with another accent. But my output is from gcc and there is no control over the fact that it uses an accent and a single quote around a name.
(2) Can someone tell me how to do the grep so it does not give the ">" prompt but instead locates "xcvr" in my example?
View 4 Replies
View Related
Dec 10, 2010
regex in grep? I need to match ANYTHING in the following with any character combination (something like * in findstr in C): grep "Delivery of nonspam" /var/log/mail.log | grep "to [URL]"
View 1 Replies
View Related
Apr 11, 2011
I want to match some filename in some text, but the filenames I have no control of, so "[" can "]" can appear in the filenames.so do I always have to use sed to addslashes to these variables before I have to grep them? and what other characters have I missed other than "[", "]", "."?
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
Mar 27, 2010
1.What character instructd the shell to interpret a special character as an ordinary character?
2.What directory contains some of the utilities available on the system in the form of binary files?
3. What command is used to search the location of a utility?
4. What command is used to instruct the editor to write the file and quit the editor?
5. What key quits the more utility and displays the shell prompt?
6. What command starts a child shell as the super user, taking on root's identity and environment?
7. Which wildcard characters can be used for searching all the files in the system that start with "A"?
8. The user name or login name of the super user is????
[Code]....
View 10 Replies
View Related
May 7, 2011
How to grep a string like "ab?c12345678" where 3rd character is unknown, while other characters are known.
View 2 Replies
View Related
Aug 30, 2009
I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:
<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">
I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">
All I need to do is duplicate the line but replace "normal" with "thumbnail"
Each file can have multiple img src tags with different numbered jpgs.
I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?
View 2 Replies
View Related
Feb 3, 2011
I need to add some text using sed before and after the matching pattern. Does any one have any clue?e.g.cat /my/file | sed -e "s/first pattern/New Pattern/g" . /my/file.bakNow I need a result like New Pattern
View 7 Replies
View Related
Apr 1, 2011
if the given pattern exists in the file with the very next line starting and endingwith the same pattern , delete the line that starts and ends with the given pattern.So upon running on this file
hai people<PATTERN> we had
<PATTERN>a lot of fun<PATTERN>
writing scripts
[code]....
View 6 Replies
View Related
May 17, 2010
I am trying to split a pattern in perl and so far I cannot get it to work. I have a pattern that looks like this:
76|2455311|2455312|00:00:00|00:00:00|Once|0|Donkey | |
I always need to print out the 8th field. So in this case donkey. Here is what I have so far:
Code:
#!/usr/bin/perl
use strict;
use warnings;
[Code].....
View 6 Replies
View Related
Mar 11, 2010
I'm working on a backup script which takes the following input:
Code:
RevBackup.sh <options> <source> <target>
The problem I'm having is that the source and target might contain spaces in the path. ie. /home/eRJe/My Documents
I would like the script to ignore " " (backslash-space) as being a delimiter. how could I do this without stopping a normal space from being a delimiter?
I could do this with IFS. But so far I have only found info about setting a delimiter and not to "ignore" one
View 4 Replies
View Related
Oct 11, 2010
I want to go through a log file and find pattern1 and then a pattern2 only after pattern 1.So for example I want to know howManyRecords was in 13:30.I figured I grep for "start time for the job" and then only after that (and before the next occurence of that) grep for "howManyRecords". Is this a sane way?
View 1 Replies
View Related
Apr 4, 2010
yes, this is a homework question, but no - I'm not trying to get anyone to do it for me. I think that I am really close, but can't quite get one small aspect to work. in gawk, I want to include a variable name in the search string, but the below code doesn't work.
read -p 'Login name please? ' uLogName
userID=$(gawk -F: '/"$uLogName"/{print $3}' /etc/passwd)
echo $userID
[code]...
View 3 Replies
View Related
Sep 6, 2010
I'm looking for a solution of pattern detection in the logs and then allows to send me an email notification if it detects the previously specified term.I use already Logwatch, but I do not know if it is possible to configure it for that use.
View 1 Replies
View Related
May 11, 2011
Any solution using awk/sed/regexp or other standard linux utility (this is for a mix of RH versions)? I am dealing with some very large application log files. I want to see everything that has been written to the log since the last application restart.
For an example take a log file like this:
Code:
# cat test.log
1 msg
2 msg
3 restart 1
4 msg
5 restart 2
6 msg
The following command is close to what I want:
Code:
# awk '/restart/,G' test.log
3 restart 1
4 msg
5 restart 2
6 msg
But the awk command grabs the first restart not the last. If it was working the way I wanted I would see something like this:
Code:
# awk '/restart/,G' test.log
5 restart 2
6 msg
So, I need something in that search pattern that says look for the last occurrence. I know how to do this with a pipe line - I could reverse the file and then do a similar awk and reverse back, or I could find the number associated with the last restart and then use that in the awk search. But these just take too long because the file is too big.
View 14 Replies
View Related
Jun 3, 2011
I am new to perl and not able to understand all the pattern matching.
I using this script to send the status to another Nagios server using ncsa. Nsca don't transmit "()" So I need to remove them before sending.
Currently I am using
Code:
for the string
Quote:
This is working fine but its is not working when there is change inside the bracket for e.g (6290)
I want to change this code to work for any change with in the brackets.
View 14 Replies
View Related
Jun 12, 2011
Is there a convenient method to find a text pattern that extends over several lines? In this case:
Empty line
LineConsistingOfSingleWord
Preferably to return the line number where the pattern occurs to determine the first such after a known line number. In other words, in order to extract a block of text from within a file.
View 3 Replies
View Related
Feb 23, 2011
I'm fairly new to Perl and regular expressions. I have a large collection of files with their file names in the following general format: string - another string with spaces (2004) [year].ext I would like to know how I could create a regex to separate out:
the first string
another string with spaces
year
extension
If you know of a better way of doing it without regular expressions, I would be happy to hear that way too.
View 13 Replies
View Related
Apr 8, 2011
i need to add this line nameserver 208.67.122.221 from ISP before the first nameserver already exists in resolv.conf in all workstations i know
Code:
sed '/nameserver/ i
ameserver 208.67.122.221'
but that insert it on every line after nameserver not only before the first one
Code:
# blah blah
# blah blah
domain mydom.com
[code]....
View 3 Replies
View Related