Sponsored Content
Top Forums Shell Programming and Scripting grep for a string until instance of a space Post 302576943 by terrell on Sunday 27th of November 2011 03:52:44 PM
Old 11-27-2011
grep for a string until instance of a space

Hey guys,

I'm having a bit of trouble getting this to work using either sed or grep. It's possible awk might be the ticket I need as well, but my regulat expression skills aren't quite up to the task for doing this.

I'm looking to grep for the string ERROR from the following log up until any instance of a space.

Here's an example of the log.

Code:
[24/Nov/2011:14:11:15] /root/bin/dbbackup.sh: started
[24/Nov/2011:14:11:15] 12591 > /var/run/dbbackup.pid

[24/Nov/2011:14:11:15] example.com started	1/3

[24/Nov/2011:14:11:15] example2.com started	2/3
[24/Nov/2011:14:11:15] ERROR: example2.com failed
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)

[24/Nov/2011:14:11:15] example3.com started	3/3
[24/Nov/2011:14:11:15] ERROR: example3.com failed
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)

[24/Nov/2011:14:11:58] /root/bin/dbbackup.sh: Finished after 0min and 43sec

If the grep was successful, my output would basically look like this:

Code:
[24/Nov/2011:14:11:15] ERROR: example2.com failed
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)

Code:
[24/Nov/2011:14:11:15] ERROR: example3.com failed
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)
mysqldump: Couldn't execute 'show create table `bbs`': Can't open file: 'bbs.ibd' (errno: 1) (1016)

Any help on this is appreciated. thanks!^_^

Last edited by terrell; 11-27-2011 at 05:04 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find the first instance after a string

I have this file (below) and need to get out specific data that appears after OSE1_1.FIX, but before OSE1_2.FIX. Specifically I need to get all of the data after "ROW80_20:", "ROW80_21:", "ROW80_22:" & "ROW80_23:" then I need to do the same for data the appears after OSE1_2.FIX, but before... (2 Replies)
Discussion started by: josslate
2 Replies

2. AIX

grep not working when search string has a space in it

Hi, I am trying to grep a string which has two words separated by space. I used a script to grep the string by reading the string in to a variable command i used in the script is echo "enter your string" read str grep $str <file> it is working fine when the entered string is a single... (3 Replies)
Discussion started by: sekhar gajjala
3 Replies

3. UNIX for Dummies Questions & Answers

Matching exact string with blank space using grep

hi! i'm trying to get grep to do an exact match for the following pattern but..it's not quite working. I'm not too sure where did I get it wrong. any input is appreciated. echo "$VAR" | grep -q '^test:]name' if ; then printf "test name is not found \n" fi on... (4 Replies)
Discussion started by: jazzaddict
4 Replies

4. Shell Programming and Scripting

Search text file, then grep next instance of string

I need to be able to search for a beginning line header, then use grep or something else to get the very next instance of a particular string, which will ALWAYS be in "Line5". What I have is some data that appears like this: Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line1 Line2 ...... (4 Replies)
Discussion started by: Akilleez
4 Replies

5. Shell Programming and Scripting

grep second instance of same string

Hi all, i am new to unix scripting in ksh or any shell for that matter. I have downloaded a xml file from a website and saved on my local harddrive. inside the xml, the same tag is listed multiple times. <title>Tonight</title> <title>Thursday</title> <title>Friday</title>... (6 Replies)
Discussion started by: scubasteve39
6 Replies

6. Shell Programming and Scripting

How can I just grep one instance of a word in the file

I want to grep some information out of the dmidecode but when I type dmidecode | grep Memory I get several instances of the word. Is there a way I can just choose which instance I want to display? (8 Replies)
Discussion started by: jcnewton13
8 Replies

7. Shell Programming and Scripting

Grep line with all string in the lines and not space.

I want to write the syntax so does not count line with no space. So currerntly it is showing lines as 5, but i want to show 4. # cat /tmp/mediacheck | sort -u | grep -vi " " | awk '{print $1}' | wc -l BA7552 BAA002 BAA003 BAA004 (6 Replies)
Discussion started by: Junes
6 Replies

8. UNIX for Advanced & Expert Users

Grep the only instance name

Hi, I want to get the only application name from the server. Ex: if i give $ ps -ef | grep bw. It will show all BW process with entire path. It will little confuse to list out the process. Can anyone have syntax to get only the instance name. I need this for be, hawk,ems also. Please... (2 Replies)
Discussion started by: ckchelladurai
2 Replies

9. Shell Programming and Scripting

One instance of comparing grep and awk

Hi. In thread https://www.unix.com/shell-programming-and-scripting/267833-grouping-counting.html rovf and I had a mini-discussion on grep and awk. Here is a demo script that compares the awk and grep approaches for this single problem: #!/usr/bin/env bash # @(#) s2 Demonstrate group... (1 Reply)
Discussion started by: drl
1 Replies

10. UNIX for Beginners Questions & Answers

Grep command in Linux in a script where the search string has a space

I have a file xyz with the following content PPPL 0123 PPPL 0006 POFT 0923 POFT 1111 WENT 2323 SEND 2345 I also have another file named MasterFile where it contains the above mentioned data million times with different digits at the end for example some times it contains SEND 9999 or WENT... (4 Replies)
Discussion started by: knijjar
4 Replies
BZEXE(1)						      General Commands Manual							  BZEXE(1)

NAME
bzexe - compress executable files in place SYNOPSIS
bzexe [ name ... ] DESCRIPTION
The bzexe utility allows you to compress executables in place and have them automatically uncompress and execute when you run them (at a penalty in performance). For example if you execute ``bzexe /bin/cat'' it will create the following two files: -r-xr-xr-x 1 root bin 9644 Feb 11 11:16 /bin/cat -r-xr-xr-x 1 bin bin 24576 Nov 23 13:21 /bin/cat~ /bin/cat~ is the original file and /bin/cat is the self-uncompressing executable file. You can remove /bin/cat~ once you are sure that /bin/cat works properly. This utility is most useful on systems with very small disks. OPTIONS
-d Decompress the given executables instead of compressing them. SEE ALSO
bzip2(1), znew(1), zmore(1), zcmp(1), zforce(1) CAVEATS
The compressed executable is a shell script. This may create some security holes. In particular, the compressed executable relies on the PATH environment variable to find gzip and some other utilities (tail, chmod, ln, sleep). BUGS
bzexe attempts to retain the original file attributes on the compressed executable, but you may have to fix them manually in some cases, using chmod or chown. BZEXE(1)
All times are GMT -4. The time now is 09:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy