How to grep a portion of line

Mysql log has something like:

I want to grep only the portion "ernie-1328697839.1233158" from each line. How to do this?

Suppose you have the log ina file called "file", here's the code you want to execute:

awk -F "'" '{ print $2 }' file | awk -F "-%" '{ print $1 }'
1 Like

Now i want a script that will scan the mysql.log file and if it finds 5 consecutive instances of the same line then it would execute certain commands.

if [ `sed "s/.*\(ernie-1328697839.1233158\).*/\1/" mysql.log | wc -l` -ge 5 ]; then echo yes; fi
1 Like

To be more precise:

1) The script will scan the mysql.log file in real time(something like tail -F mysql.log)
2) If it encounters 5 consecutive identical lines then it would invoke some commands.

Any help will be highly appreciated.

  1. Your requirements keep changing over the posts.
  2. One way to achieve requirement mentioned in post #5 is to write a script that will keep scanning the file until a certain condition is met.

1) Extremely sorry for that.
2) How? Can you help with the basic logic.