In a sample log message we have20161110-15:29:39.707932513|8=FIX.4.29=031735=D34=00000389552=20161110-15:29:39.70749=413050=11156=DDG109=4130115=EAGLE7|EAGLE7116=eagle_fix_trader11|eagle_fix_trader11144=DAU|E7T9139=eagle_fix_trader119195=U439=805440=150854029208=221=1167=FUT55=14198040=259=054=111=41301110400144=0000035.0000000038=00000000760=20161110-15:29:39.70710=092from the above how can you display only the 9139 value so it looks like9139=eagle_fix_trader11I used the below commandls | grep -Eo '9139=[a-z]{0,8}' 9707le8.logBut I only get9139=eagleinstead of 9139=eagle_fix_trader11Any ideas?
BASH:How Grep and display a set of values
shell script;grep;ls
First of all, the ls | there is completely useless. You want to search inside the file 9707le8.log, not in the list of files and directoris in your current directory (which is what ls prints). In any case, grep ignores any input piped to it (| grep) when it is also given a file name to search for on the command line as you have. That said, your regular expression means find the string 9139=, followed by <= 8 lower case letters. However, there are only 5 letters after the =; the 6th character is an _ and that isn't part of the [a-z] character group. A simple solution is to add it to the class:$ grep -Eo '9139=[a-z_]{0,8}' 9707le8.log9139=eagle_fiNow, since you want 9139=eagle_fix11, you need to increase the characters:$ grep -Eo '9139=[a-z_]{0,18}' 9707le8.log9139=eagle_fix_traderThis time, the problem is that you're not matching the numbers since [a-z_] doesn't include them. So, you want something like this:$ grep -Eo '9139=[a-z_0-9]{0,18}' 9707le8.log9139=eagle_fix_trader11Or, for a more general case, where you want 9139= by a string of lower case letters or _ and then two numbers, you can use:$ grep -Eo '9139=[a-z_]+[0-9]{2}' 9707le8.log9139=eagle_fix_trader11Or, with GNU grep:$ grep -Po '9139=[a-z_]+\d{2}' 9707le8.log9139=eagle_fix_trader11