Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide text output for none-block selection mode #6

Closed
mailsanchu opened this issue Nov 25, 2021 · 13 comments
Closed

Provide text output for none-block selection mode #6

mailsanchu opened this issue Nov 25, 2021 · 13 comments

Comments

@mailsanchu
Copy link

No description provided.

@suntong
Copy link
Owner

suntong commented Nov 26, 2021

No description provided, so I have to guess what you meant.

$ cat /tmp/cascadia.xml | cascadia -i -o -c 'div' --piece SelText='p'
SelText
Name: John Doe

You meant this SelText?

You can change it to whatever you want:

$ cat /tmp/cascadia.xml | cascadia -i -o -c 'div' --piece I_Want='p'
I_Want  
Name: John Doe  

Or remove it completely with the help of other tools like sed.

The cascadia is a *nix tool and it is built with the Unix philosophy, which emphasizes building simple, short, clear, modular, and extensible code that can be easily maintained and repurposed by developers other than its creators. The Unix philosophy favors composability as opposed to monolithic design.

To remove it completely with sed:

$ cat /tmp/cascadia.xml | cascadia -i -o -c 'div' --piece SelText='p' | sed '1d'
Name: John Doe  

HTH

@mailsanchu
Copy link
Author

I meant Or remove it completely
I wanted to find the release version for this Github page
https://github.com/puppeteer/puppeteer/releases

But you gave me the answer I want.

Thank you Thank you

@mailsanchu
Copy link
Author

My final version for the future visitors of this page
cascadia -q -i "https://github.com/puppeteer/puppeteer/releases/latest" -o -c "div[class='flex-1']" --piece SelText='h1' | grep -E --color=none '[v0-9.]'

@suntong suntong changed the title How to not print SelText while using it Provide text output for none-block selection mode Nov 26, 2021
@suntong
Copy link
Owner

suntong commented Nov 26, 2021

OK, re-title it to "Provide text output for none-block selection mode"

@suntong
Copy link
Owner

suntong commented Nov 26, 2021

Basically the ask is to get the text part from this output:

$ cascadia -q -i "https://github.com/puppeteer/puppeteer/releases/latest" -o -c "div[class='flex-1'] h1"
<h1 data-view-component="true" class="d-inline mr-3">v11.0.0</h1>

@mailsanchu
Copy link
Author

Yes the above comment is correct ^^

@mailsanchu
Copy link
Author

I think we can close this ticket. I gave a fully working example.ANother one give below as well
cascadia -q -i "https://github.com/puppeteer/puppeteer/releases/latest" -o -c "div[class='flex-1'] h1" | xpath -q -e "//h1/text()"

@suntong
Copy link
Owner

suntong commented Nov 27, 2021

$ cascadia -q -i "https://github.com/suntong/cascadia/releases/latest" -o -c "div[class='flex-1'] h1"
<h1 data-view-component="true" class="d-inline mr-3">v1.2.6</h1>

$ cascadia -q -i "https://github.com/suntong/cascadia/releases/latest" -o -c "div[class='flex-1'] h1" -t
v1.2.6  

$ cascadia -q -i "https://github.com/suntong/cascadia/releases/latest" -o -c "div.flex-1 h1" -t
v1.2.6 

$ cascadia -q -i "https://github.com/suntong/cascadia/releases/latest" -o -c "h1.d-inline.mr-3" -t
v1.2.6  

$ cascadia -q -i "https://github.com/suntong/cascadia/releases/latest" -o -c "div.flex-1 h1" -t | hexdump -C
00000000  76 31 2e 32 2e 36 09 0a  0a                       |v1.2.6...|

$ cascadia -q -i "https://github.com/suntong/cascadia/releases/latest" -o -c "div.flex-1 h1" -t -d '' | hexdump -C
00000000  76 31 2e 32 2e 36 0a 0a                           |v1.2.6..|

$ cascadia -q -i "https://github.com/puppeteer/puppeteer/releases/latest" -o -c "div[class='flex-1']" -t -R; echo done

    12.0.0
    Latest
      
          
      
  

                This commit was created on GitHub.com and signed with GitHub’s verified signature.
          

done

$ cascadia -q -i "https://github.com/puppeteer/puppeteer/releases/latest" -o -c "div[class='flex-1']" -t; echo done
12.0.0
    Latest
This commit was created on GitHub.com and signed with GitHub’s verified signature.

done

$ cascadia -q -i "https://github.com/puppeteer/puppeteer/releases/latest" -o -t -c "h1.d-inline.mr-3" -c "div.flex-1 strong"
12.0.0  
verified signature

@suntong suntong closed this as completed Nov 27, 2021
@mailsanchu
Copy link
Author

Super cool

@mailsanchu
Copy link
Author

Hey I just noticed it is not doing a trim correctly. It is not a big issue. Just want to let you know. Please see screenshot
image

@suntong
Copy link
Owner

suntong commented Jan 11, 2022

can you give me a minimum case to duplicate, not just a screenshot please.

@suntong
Copy link
Owner

suntong commented Jan 11, 2022

-t will grab everything as a single output, and trimming will only happen to its leading and trailing white space of that massive text, not each line.

@mailsanchu
Copy link
Author

:) Hmm that is why my grep was not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants