Programming :: How To Grep Pattern Which Is Split In 2 Lines?
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
ADVERTISEMENT
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
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
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
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
Mar 23, 2010
I am trying to edit a print file.
For every occurence of the ^L form feed character I need to remove 5 blank lines after it but still keep the ^L.
I am a rare user of sed and am ok with the basics but am struggling with this.
View 4 Replies
View Related
Apr 12, 2010
I have two files, where the 1. file has special lines that need to be updated by lines from a 2. file:file1:
foo
foo
foo 0.00 0.00 0.00 pattern
[code]....
View 1 Replies
View Related
Jun 6, 2010
I have a file which contains milion of records. It contains 12 columns seperated by "||" (delimeter).
First two fields contain first name and last name of a person. Now my requirement is to delete all those records from this file for which:
First two fields does not contain any alphabet.
For e.g i have below mentioned records in file:
gaurav||gandhi||123||456||789
#a%bcd||123abc||89|90||91
12345||@@@||89||123||234
***||!!!!||98||76||90
Now, last two lines should be removed from this file since first two fields does not contain any alphabet for these two records.
View 12 Replies
View Related
Apr 24, 2010
Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.
[code]....
My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:
[code]....
Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.
[code]....
how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?
View 10 Replies
View Related
Sep 16, 2010
I have such a file(test.txt):
abc 123 456
abc 256 145
axd 125 225
[code]...
View 8 Replies
View Related
Jun 4, 2010
How can i split a string like this,
Code:
This is my first line.
This is my second line.
This is my third line.
into,
Code:
"This is my first line.", "This is my second line.", "This is my third line."
in C++.
i.e. split the code at every new line
View 11 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
Jun 9, 2009
I would like to know how I can get the ouput from the following dmidecode command in example 1 to look like example 2 without having to grep -v all the unwanted lines.Is there a way in awk or sed?Example 1
Code:
Processor Information
Socket Designation: Socket 1 CPU 1
[code]...
View 7 Replies
View Related
Sep 17, 2010
I have such a file(test.txt) as below:
[code]...
I want to use grep to fetch the lines contain 'AB_001'.
[code]...
get the first 2 lines, not the 'AB_0011/10/105'.
View 2 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
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
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
Oct 14, 2010
How do yo find a pattern with sed or awk and then:
- add a # at the beginning of the line containing it
- and add a # at the beginning of the following 2 lines, too?
Say, I want to comment out the line containing "which 0launch" and the two lines following it:
if [ -x "`which 0launch`" ]; then
exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
fi
Expected result:
#if [ -x "`which 0launch`" ]; then
# exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
#fi
I need this because I do not want to comment out every line containing "fi", just the "fi" of this specific if statement.
View 3 Replies
View Related
Apr 14, 2010
I have to use sed with this problem, and sed is extremely complicated, they could probably teach a whole class on this entire function.
Here's an example to show what I need to do:
Code...
how would I say that every line before I reach the first match of "sweet" should be deleted so that the output will look like: Code...
View 9 Replies
View Related
Aug 5, 2010
when I run the following command:
awk -F, '{print $10 "," $5 "," $1 "," $3 "," $4 "}' myfile > tmpfile
tmpfile displays the lines but they are all cut off and placed on the line below at the same point.
View 1 Replies
View Related
Jan 25, 2011
I have 8 files, and each contains around 2000 lines. I want to search the particular word in these files between line number 1500 to 2500.
The output should look like:
sample_1.txt :
1510:declare var testing
sample_2.txt :
1610:declare var testing
sample_7.txt :
1610:declare var testing
sample_10.txt :
1710:declare var testing
Is it possible to use grep for this task?
View 4 Replies
View Related
Mar 14, 2011
I have a file called test. It has the following contents.Code:there youI want the output to be.Code:replaced youI am trying to use the sed command to replace every occurance of "hey newline there" with "replaced". I tried the following naive apporach.Code:sed 's/heythere/replace/' testThis gives a result containing the same data as the test file.
View 3 Replies
View Related
Nov 1, 2010
I'd like to split a file into two, where the first file is the first two lines and the second is the remaining lines (third line to EOF).
View 2 Replies
View Related
Nov 5, 2010
Using sed, I am trying to append four commas ',,,,' at the end of lines containing the pattern 'Response' in a text file with lines such as these:
6,Pulse,50,254968,14886,NA,,,,
7,Picture,8,265157,0,1,15045,2,0,15000
7,Response,1,271553,6396,1
7,Pulse,50,274969,9812,NA,,,,
8,Picture,1,290232,0,1,15045,2,0,15000
8,Pulse,50,294969,4737,NA,,,,
[Code].....
View 1 Replies
View Related
Jul 27, 2011
A function by name abc is called in many files. I want to copy all the lines with the function call to an output file.A simple grep on function name doesn't help me as the function call is spanning across multiple lines as follows:
abc(parameter1,
parameter2,
parameter3);
So I want to copy all the three lines (till semicolon) to the output file.The problem is because there are more than 200 calls for the same function and I cannot do it manually
View 2 Replies
View Related
Aug 7, 2010
I know how to use grep to output a line that matches a string. But what if I also want to output one line above every line containing a matching string, how do I do that?
View 1 Replies
View Related
Feb 21, 2011
Does anyone know why something like:
echo lowercase | grep [A-Z]
Would still return the lowercase line even tho there is no match?
Using --color will show there is no match but the line is still returned.
I am still new but from what i've learned this should not work like that. ubuntu 10.10
View 13 Replies
View Related