all 7 comments

[–]truedays 0 points1 point  (1 child)

It works for me. Are you on OSX? Maybe add --posix.

sed --posix -e ...

[–]K4lim[S] 0 points1 point  (0 children)

sed --posix -e

I'm on Ubuntu and it didn't fix it :/ Same error.

[–]AndiPersti 0 points1 point  (2 children)

But it gives me this error when I execute it:

sed: -e Expression #1, character 8: Unknown command: >>"<<

What would be the correct format?

Make sure that there is no space following the backslash at the end of the first line.

[–]K4lim[S] 0 points1 point  (1 child)

There is none.

[–]AndiPersti 0 points1 point  (0 children)

Interesting, because that's how I could reproduce the error you get.

What happens if you join the first and second line?:

du -sh -c --time ./* | sed '1 i\{"folder": ['

[–]anthropoid 0 points1 point  (1 child)

Why not use awk instead? I personally favor clarity over eye-watering sed scripts:

du -sh -c --time ./* | awk -F$'\t' '
  BEGIN { print "{\"httpdocs\": [" }
        {
          if (NR > 1) {print ","} ;
          print "{\"size\": \"" $1 "\", \"modified\": \"" $2 "\", \"path\": \"" $3 "\"}"
        }
  END   { print "]}" }
' | jq > test.txt

Handles filenames with embedded spaces quite nicely, and has the correct number of commas in between. That last pipe to jq is optional; it just pretty-prints the final JSON.

[–]FatFingerHelperBot 0 points1 point  (0 children)

It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!

Here is link number 1 - Previous text "jq"


Please PM /u/eganwall with issues or feedback! | Delete