I'm writing a recon shell script and I would like to parse the output of odat sidguesser so i can save only the found SID's into a file or variable. For example. I have the string;

[+] SIDs found on the server: XE,XEXDB

What I'm trying to do is parse this output so only XE,XEXDB remains so I can store it in a file or variable to further enumerate / run odat passwordguesser with the SID. How can i use sed or awk or grep etc... to get all valid SID's without knowing how many will be found? I'm able to get the SID's by doing,

cat oracle-sid.txt | grep "server:" | rev | cut -d " " -f 1 | rev

This works for my purposes since XE,XEXDB is all considered 1 string and i can write more logic to loop through it etc.... However, In the case where the SID's were separated by spaces, How would one go about parsing every SID or string after the word/delimeter, "server:" ?

  • Is it fair to say that all the text up to and including server: is useless to you, and you just want the part that comes afterward, as-is? Or do you need the SIDs broken out one by one?
    – Jim L.
    Aug 1, 2019 at 22:34
  • 1
    For the first part, eliminating the useless part of the string, your question is a duplicate of this one. For the second part, splitting up a string based on a delimiting character, your question is a duplicate of this one.
    – Jim L.
    Aug 1, 2019 at 22:40
  • 1
    Is XE,XEXDB one of these SID things you mention, or is it two of them?
    – roaima
    Aug 1, 2019 at 22:53

1 Answer 1

$ sed -n -e 's/^.*server: //p' oracle-sid.txt

On matching lines, the sed script deletes everything from the beginning of the line to "server: " (including the trailing space), and then prints the modified line. Non-matching lines are ignored (i.e. not printed).

If you want to keep the IP address and port as well:

$ sed -e -e 's/^.* \([0-9.:]\+\) server: /\1\t/p' oracle-sid.txt        XE,XEXDB

This will do the same as the first version, but include the IP:Port and a TAB character.

  • Thank you! Worked like a charm.
    – MrPMillz
    Aug 2, 2019 at 8:10
  • you're welcome. btw, upvoting and/or accepting an answer (by clicking on the tick mark to the left) is how we say thanks on stackexchange sites
    – cas
    Aug 2, 2019 at 8:12
  • 1
    I tried to but I don't have enough reputation points yet. Once I get more than 15 reputation points I will click the up arrow for sure. Thanks again.
    – MrPMillz
    Aug 2, 2019 at 8:31

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.