Skip to content

Instantly share code, notes, and snippets.

@sacgov
Last active February 6, 2022 13:26
Show Gist options
  • Save sacgov/39b155d5a4fdd8f190cdfe6e888529ef to your computer and use it in GitHub Desktop.
Save sacgov/39b155d5a4fdd8f190cdfe6e888529ef to your computer and use it in GitHub Desktop.
converts a file into json array with each line as the string
#!/bin/sh
# -i is in place and -e is the regular expression
# add a " to start of each line
sed -i -e 's/^/"/' input
# add a ", to end of each line
sed -i -e 's/$/",/' input
# add [ to the first line
sed -i -e '1s/^/[/' input
# $ is a Sed address that matches the last input line only
# remove comma in the last line
sed -i -e '$ s/.$//' input
# add a ] at the end of file
sed -i -e '$ s/$/]/' input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment