Fork me on GitHub
#babashka
<
2023-04-11
>
furiel10:04:33

Hello, I am converting a shell script to babashka, and one line containing a grep | some awk command | sort | uniq chained together kept me wondering how to handle the newlines properly. The output is coming from a babashka/process as a string. I am using clojure.string/split-lines, which deletes the terminating newline characters. Due to that, I need to put them back when assembling the string back again. This is what I am experimenting right now:

(net.cgrand.xforms/str
 (comp
  (filter #(re-find #"test" %))
  ;; awk related code
  (x/sort)
  (distinct)
  (map #(str % "\n")))
 (string/split-lines "testline1\nsome-other-line\nthis is a test again"))
which gets the job done, but I was wondering if there is a better way that does not involve juggling with newline characters.

borkdude10:04:23

what do you want to do with the lines eventually?

furiel10:04:40

Print them to console

borkdude10:04:46

if you want to print them you can do:

(run! println lines)

furiel10:04:30

Sounds great. Thank you.

๐Ÿ‘ 2
borkdude10:04:27

Is there anyone going to the conj who I could order some stickers for so they can give it to people over there? I'm afraid it's going to be too short on time (and I'm terrible with making plans) but maybe someone near me is going there so I can actually ship them this week.

seancorfield16:04:21

Could you order them online for the US and have them delivered to the hotel for someone who would be staying there?

borkdude17:04:37

I think I could do that

Daniel Gerson20:04:08

Didn't realise babashka wasn't promesa compatible. Had planned to use a papillon fork that I did to get some context flowing between jobs. ... ๐Ÿงต

Daniel Gerson20:04:33

What are people using to get interceptors into bb not wedded to an http request response model?

borkdude20:04:02

I think promesa could maybe be made bb compatible but due to deftype + JVM interfaces it currently isn't

Daniel Gerson20:04:59

Given I don't need async for the bb use case, I will just string interceptors together to get this done with no wrapping execute. However, I now have a reflex to reach for an interceptor library for such things and so I felt compelled to write the question. FYI my fork will hopefully soon be obsolete https://github.com/lambda-toolshed/papillon/issues/2 Nothing further required for now ๐Ÿ˜„

borkdude20:04:00

Babashka reaches 3300 stars on Github! โญ babashka โญ https://github.com/babashka/babashka/stargazers And almost 1300 of you over here! ๐ŸŽ‰

๐ŸŽ‰ 48
โญ 14
clojure-spin 2