Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Linux


Advertisements:










Programming :: Awk Command - Search Pattern To Look For Last Occurrence


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 (Posted: 05-11-2011, 04:25 AM)

Sponsored Links:

Related Forum Messages For Linux category:
Programming :: Sed Command Stuff - Search For Pattern?
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

Posted: 10-03-2010, 09:24 PM

View 2 Replies!   View Related
Programming :: Search A File For A Particular Pattern And If Pattern Found Replace The Line With New Text?
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?

Posted: 02-24-2010, 11:10 AM

View 1 Replies!   View Related
Programming :: If Statement Pattern Search / End Of Pattern Special Character?
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

Posted: 04-29-2010, 06:16 AM

View 3 Replies!   View Related
Programming :: Need Help To Search Pattern In Xml File
I need your help in searching one pattern in below xml file , When i open this xml file in vi editor it open as single line..in this file i want to search for pattern which is in Red (ReadRDPPackagesResponse xmlns583) and then i want cut p583 from this pattern , can any body plz help me how to search for this , (Note that when i open this file in vi editor it open as single line).

Posted: 10-24-2008, 11:52 AM

View 2 Replies!   View Related
Programming :: Gawk - Using Variable In Search Pattern?
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]...

Posted: 04-04-2010

View 3 Replies!   View Related
Programming :: Replace Occurrence Of A String In Many Files In One Command?
I used a command Code:

grep -r err_sys ./
its output is
Code:
./tcpclitime.c:err_sys("socket error");
./tcpclitime.c:err_sys("connect error");
./tcpclitime.c:err_sys("write error");
./tcpclitime.c:err_sys("shutdown error");
./tcpclitime.c:err_sys("read error, n = %d", n);
[Code].....

Is it possible some how to replace all the occurrences of word err_sys by printf.

Posted: 10-30-2010, 05:56 AM

View 1 Replies!   View Related
Programming :: Search File By Pattern And Then Delete Corresponding Lines In Shell?
I have such a file(test.txt):

abc 123 456
abc 256 145
axd 125 225

[code]...

Posted: 09-16-2010, 08:58 AM

View 8 Replies!   View Related
Programming :: S/ Command Won't Replace Two Occurrences Of Pattern On Same Line
Here's the actual line of code, which exists in a bash script:

Code:

I want to replace instances like this:

Code:

with this:

Code:

Using this:

Code:

Which works great when there's only ONE of the pattern on the line. But in a case like the "actual line" I posted first, where there are two patterns, separated by a slash, only ONE gets replaced

Watch:

Code:

Why? There must be (among many other things) something I'm not knowing about sed, that's causing this.

-- I'm currently using the ~ (tilde) as the separator in the sed command. It doesn't matter, I've used / ~ and % with no difference.

-- As a test, I tried putting a different character(s) in the middle of the original pattern instead of the / but that made no difference.

-- I've come up with various similar but slightly different regexs that will do this replacement, but they all have had this same result.

-- I tried the sed single-quoted, double-quoted, and unquoted; the latter fails to execute, and the formers both work as described here: wrong.

Posted: 12-15-2009, 10:33 PM

View 7 Replies!   View Related
General :: Bash - Search For A Text Pattern?
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.

Posted: Nov 28 10 at 15:08

View 5 Replies!   View Related
General :: Search For A Pattern Between Lines 1500 To 2500?
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?

Posted: Jan 25 at 7:43

View 4 Replies!   View Related
General :: How To Make Grep To Search A Pattern In Only Specific File Type?
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.

Posted: 03-06-2010, 12:12 PM

View 7 Replies!   View Related
Programming :: Search All Files For String - Strings Command?
I need to search all files on a server for certain string. I've been told the strings command would be best. I need it to search all files in all directories. I'm thinking of using the strings command that can do a directory, within a script that does all directories. I have been a linux user for a while but my scripting and skills are not great.

Posted: 03-28-2008, 01:14 PM

View 4 Replies!   View Related
Programming :: Find Command To Search For All The File In The Particular Folder?
how to use find command to search for all the file in the particular folder?my script as below

find . -name "*" > $BASE/file
if [ `more file | wc -l` -gt 0 ]; then
echo "dp"
fi

output of my results will always include a . (dot)which I dunwan it include the dot.

Posted: 08-02-2011, 11:31 PM

View 11 Replies!   View Related
Programming :: Replace 2nd Occurrence Of A String In A File - Sed Or Awk?
I know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.

For example, here is a file:

Code:
John
Betty
Jack
Ron
Jack
Paul

So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.

Posted: 04-05-2010, 01:56 PM

View 10 Replies!   View Related
Programming :: Web Development - Command To Search String Through Files On A Server?
I am web developer I have this command find . -exec grep "Improve your score" '{}' ; -print for searching through files . I found this command but now i would like to tweak it to gain more out of it.

Posted: 04-08-2009, 03:15 PM

View 2 Replies!   View Related
Programming :: Perl - Sorting By Occurrence Of Specific Character
I have data in the following format pulled from a MySQL database in an array:

I would like to find a way to sort by # of favorites (they are comma-separated) if possible, so that someone with 8 favorites comes before someone with 4, regardless of length (a solution proposed elsewhere).

I've tried playing with my SQL query to sort by the # of commas in the 'favorites' field, but that hasn't lead anywhere either (that would be a very simple fix, should I get it to work).

I've looked at using tr/// but I can't quite figure out how to sort by its results.

Posted: 09-26-2007, 01:08 PM

View 5 Replies!   View Related
Programming :: Add Time Of Occurrence For Mouse Event In Xinput?
i need to have the time of occurence for mouse event in xinput,right now i run

Code:
xinput test <device_id> >log.txt
(for finding device_id using xinput list)

[code]...

Posted: 01-24-2011, 09:02 AM

View 4 Replies!   View Related
Programming :: Count The Number Of Occurrence Characters In A String ?
How do I count the number of occurrence characters in a string in an efficeint way ?

How do I reverse the words in a string with out using temp variables if possible . (if not possible use temp variables ?

Why do I specify dependedcies for header files in the Makefile ?

Posted: 01-26-2011, 10:34 AM

View 2 Replies!   View Related
General :: File Matching Pattern On Command Line?
I've got files in a directory as follows:

1.png
1_thumb.png
1-1.png
1-1_thumb.png

[code]....

I want to list all the files that don't have a copy with the same filename with -1 somewhere in it. So, in the example above, the results would be 3.png.

NB: the file and its copy with "-1" in it will be the same filesize, if that helps.

Posted: Sep 9 at 13:54

View 2 Replies!   View Related
Ubuntu :: Egrep Command To Return Matches For A Group Rather Than The Whole Pattern Itself?
To put it simply I want the egrep command to return matches for a group rather than the whole pattern itself.For example:

Code:
egrep "reals([0-9]+?m[0-9]+?.[0-9]{3}s)" tmp
returns
"real 0m1.001s"

But I want it to return just "0m1.001s", the portion is the group. I can just apply egrep to whatever the first command returns but is there an easier way to do it?

Posted: January 17th, 2011

View 4 Replies!   View Related
General :: Add (not Replacing) A Pattern Match With A Similar Pattern?
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?

Posted: 08-30-2009, 10:21 PM

View 2 Replies!   View Related
General :: Find Pattern After Specific Pattern
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?

Posted: 10-11-2010

View 1 Replies!   View Related
Programming :: Add Texts Using Sed In Matching Pattern?
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

Posted: 02-03-2011, 07:39 AM

View 7 Replies!   View Related
Programming :: Setting IFS To Ignore Pattern?
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

Posted: 03-11-2010, 05:17 PM

View 4 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved