Last active
February 6, 2022 13:26
-
-
Save sacgov/39b155d5a4fdd8f190cdfe6e888529ef to your computer and use it in GitHub Desktop.
converts a file into json array with each line as the string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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