0

I have a log file which has two different type of statements.

One statement is like

LOG:Update For User 12932030 statement  @2113 set startduration='2017-01-03 00:01:30'...
LOG:Update For User 12932030 statement @2033 set startduration=endduration ...
LOG:Update For User 12932031 statement @2403 set startduration='2017-01-04 00:02:30'...
LOG:Update For User 12932032 statement  @3113 set startduration='2017-01-09 00:03:30'...
LOG:Update For User 12932033 statement @9313 set startduration=endduration ...
LOG:Update For User 12932034 statement @9126 set startduration=endduration ...

So from this I want to extract both seperately.But my current approach is like

grep -i " LOG:Update For User set startduration"  log.csv > result.csv

which does not differentiate between both.I am not sure how can I incorporate the pattern after startduration .Any help is appreciated.

  • 2
    Can you give a more examples of logs content and two types desired outputs? – Egor Vasilyev Nov 10 '17 at 8:12
  • @EgorVasilyev Is the above fine?it's basically one deals with the server time while other resets the star time to endtime – Ricky Nov 10 '17 at 8:14
  • @Ricky, which does not differentiate between both - cause you're trying to match the same pattern on all lines, that's obvious – RomanPerekhrest Nov 10 '17 at 8:16
3

Try to use grep twice:

Desired output type №1:

 grep -E "LOG:Update For User [0-9]* statement *@[0-9]* set startduration='" log.csv

LOG:Update For User 12932030 statement  @2113 set startduration='2017-01-03 00:01:30'...
LOG:Update For User 12932031 statement @2403 set startduration='2017-01-04 00:02:30'...
LOG:Update For User 12932032 statement  @3113 set startduration='2017-01-09 00:03:30'...

Desired output type №2:

grep -E "LOG:Update For User [0-9]* statement *@[0-9]* set startduration=[^']" log.csv

LOG:Update For User 12932030 statement @2033 set startduration=endduration ...
LOG:Update For User 12932033 statement @9313 set startduration=endduration ...
LOG:Update For User 12932034 statement  @9126 set startduration=endduration ...
  • I am so sorry I forgot to mention that in the LOGS after User there is @numeric which is different for each line – Ricky Nov 10 '17 at 8:29
  • @Ricky, i corrected my answer. See above – Egor Vasilyev Nov 10 '17 at 8:34
  • Sorry again missed one more thing in Logs.So sorry for the inconvineience.But i tried grep -E "LOG:Update For User [0-9]* statement @[0-9]* set startduration='" log.csv but printed empty file – Ricky Nov 10 '17 at 8:44
  • Oh i see i think i missed an asterix before @ – Ricky Nov 10 '17 at 8:52
  • @Ricky, i corrected my answer again. Your output is empty because input data has several spaces after statement – Egor Vasilyev Nov 10 '17 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.