General :: Search For A Pattern Between Lines 1500 To 2500?
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
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?
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
I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.
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.
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.
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
I'm trying to make a program to search for each blank line in a text archive, where blocks are separated by this blank lines. I want to write the number of the line in a new file "numblank.txt" I have this, but I think I have a problem with the "blank line" simbol.
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.
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.
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.
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.
I'm writing a script that edits a Maya ascii file. Inside the .MA(maya ascii file) there is a line defaultRenderGlobals. My script is supposed to find this line and according to what options they manipulate will update the lines below defaultRenderGlobals. I've got that working... but... the issue i'm having is that defaultRenderGlobals is only made when a the maya scene is made into a batch render. I want my script to manually addefaultRenderGlobals line into the .ma file if its not there and add the certain lines below it.RenderGlobals is already there I want to just manipulate whats below it. Hope this makes sense
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?
How to search multiple words in multiple lines, inside a directory including sub-directory? Pls. give easy example. I want to search the files (in /xx folder and all subfolders) that have header.h included and used x() function. I tried $grep -r "header.h" | grep -r "x(" /Folder/subfolder/ > search.log
I have installed openSuse 11.3, my computer is a Dell Vostro 1500, it has a modem, but is not recognized between the devices. I do not know why. I have not the slightest.Please, someone with enough intelligence to be humble to explain clearly and explicitly that the system can I identify and mount my modem, and can make use of it.If by chance you need some additional information, please specify to me how I can get to the place in this thread.
I am trying to construct a quick regex that will search for six lines of text without a clear line break between them. It only needs to search, not replace, as I will be using in gEdit (with regex plugin) anyway.
It's for editing subtitle files. The video player I will be using them on can only cope with 3-line subtitles, so I just need to edit any in the srt file that contain four or more. There won't be many so I can do it manually. For example:
26 00:01:47,357 --> 00:01:49,359 a motivated business professional with clearly defined goals.
[Code].....
but .* seems to mean "any character, or none", so that doesn't work. My experience of regular expressions is limited, but I do know they are very powerful when used correctly!
This should be simple but I can't seem to find what I am looking for.I want to search a text file for the existence of certain strings and execute a command if they exist, something along the lines of:
if <string> exists command or
if <any member of this list exists> command
I know how to manually search a file with grep, cat, etc., but the "if this exists" part eludes me.
I've come across an unusual requirement for a service in my Ubuntu system.Simply put, I need to find a way to search for all instances of a term in a file, delete lines containing containing that term, and delete four lines below each instance of that term. ither that, or copy the entirety of a file to a new file and skip over all lines containing the term plus four below it.This sounds kinda weird, I know. Without going too far into detail, I either have to change the logfile format for a server I'm running which is a huge pain in the butt, or I can just run a script to edit an HTML report generated from said logs. (Said report is really just for managers to peruse, and I like my log format, so I'm pursuing option 2.)
I am an intermediate linux user. However, I know nothing about solaris. I am trying to install Debian Sparc on a sun blade 2500 workstation. I was told it should work. I am able to go through the debian installation process but when the box reboots it does not boot into Debian. I have now gone through the debian install process several times and now it saids there are too many primary partitions. I tried a rescue install but it saids there are no partitions installed on disk? What am I doing wrong? I am curious if I need to pass a specific argument at the command line to boot into silo? I cannot find any relevant guidance online about this problem and I cannot believe I am the only one to stumble here.
When trying to install Debian 6.02 from a boot cd, the boot halts with the error message Kernel panic - not syncing: No init found. Try passing init= option to kernel. In looking for a solution I see a great deal about this problem occurring after messy upgrades and the like, but when when booting from a cd downloaded right from the debian website.