Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to parse a log file in bash
    text
    copied!<p>I have a log file that contains a lot of text, some of it is useless. In this log there are some lines that are important for me. The pattern for those lines are:</p> <pre><code> 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x00000001 (NEEDED) Shared library: [ld.so.1] 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] </code></pre> <p>The NEEDED keyword could be found on all lines that are important for me. The keyword between [] is the one important for me. I need to create a list of all those strings, without repeating them.</p> <p>I've done this on Python, but looks like on the machine I want to run the script there is no Python available, so I need to rework the script in bash. I know only basic stuff in bash and I'm not able to find a solution for my problem.</p> <p>The Python script I've used is:</p> <pre><code>import sys import re def testForKeyword(keyword, line): findStuff = re.compile(r"\b%s\b" % keyword, \ flags=re.IGNORECASE) if findStuff.search(line): return True else: return False # Get filename argument if len(sys.argv) != 2: print("USAGE: python libraryParser.py &lt;log_file.log&gt;") sys.exit(-1) file = open(sys.argv[1], "r") sharedLibraries = [] for line in file: if testForKeyword("NEEDED", line): libraryNameStart = line.find("[") + 1 libraryNameFinish = line.find("]") libraryName = line[libraryNameStart:libraryNameFinish] # No duplicates, only add if it does not exist try: sharedLibraries.index(libraryName) except ValueError: sharedLibraries.append(libraryName) for library in sharedLibraries: print(library) </code></pre> <p>Can you please help me solving this issue? Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload