0

I've some text output like the following:

+-------------------------+-----+--------------------------------+--------------------------------------------+
| Site                    | SSL | URL                            | Path                                       |
+-------------------------+-----+--------------------------------+--------------------------------------------+
| samplerds.test          |     | http://samplerds.test          | /Users/user01/Paths/samplexx1              |
| wpo.test                |     | http://wpo.test                | /Users/user01/Paths/wpo                    |
+-------------------------+-----+--------------------------------+--------------------------------------------+

Is there any way to parsing the text above using awk or sed to transform them into the following:

samplerds
wpo

Cheers

4
  • 2
    Anything you tried yet? Is the TLD always .test?
    – pLumo
    Apr 27 at 8:56
  • @pLumo yes, I've tried several hours and yes I can say the TLD is always .test. Because the Path (directory name can be different to the domain name which give me so much headache so far) Apr 27 at 8:57
  • 1
    And what did you try in that hours? It will help you the most if we see your attempt and explain why it did fail.
    – Philippos
    Apr 27 at 9:04
  • Is that really what you have? That looks like the result of a database query. Can't you just skip printing the headers? Also, with mysql for example, the ASCII table characters are not printed when you pipe the output somewhere. Is that what you're using maybe?
    – terdon
    Apr 27 at 10:03

1 Answer 1

3

Use awk:

$ awk -F '[ .]' 'NR>3 && !/^\+/ {print $2}' file
samplerds
wpo

or add the subdomain as field separator:

awk -F ' |\.test' 'NR>3 && !/^\+/ {print $2}' file

or with gsub to make it also work when you have subdomains:

awk 'NR>3 && !/^\+/ {gsub("\.[^.]*$","",$2); print $2}' file

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.