Created
March 31, 2024 08:35
-
-
Save rewse/a32475f3aa7ebe24d4c56be84b3560eb to your computer and use it in GitHub Desktop.
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/bash | |
trap 'my_exit 1' 1 2 3 15 | |
readonly tmpfile='/tmp/conv_googlekeep_omnivore.tmp' | |
my_exit() { | |
rm -f $tmpfile* | |
} | |
cat - | | |
jq -r '[.textContent, .userEditedTimestampUsec / 1000, .createdTimestampUsec / 1000, .labels[].name] | @tsv' | | |
perl -pe 's/^(\S+?)\\n.*?(\t.*)/\1\2/' | # Delete texts from textContent excluding the first URL | |
perl -pe 's/(\S+\t\S+\t\S+\t)(.+)/\1\"[\2\]"/' > $tmpfile # Add [] to labels | |
# Split to three files to swap | |
# Create a file including URL and SUCCEEDED | |
cat $tmpfile | | |
awk 'BEGIN{FS="\t"; OFS="\t"} {print $1, "SUCCEEDED"}' > $tmpfile.1 | |
# Create a file including times | |
cat $tmpfile | | |
awk 'BEGIN{FS="\t"; OFS="\t"} {print $2, $3}' > $tmpfile.2 | |
# Create a file including labels | |
cat $tmpfile | | |
perl -pe 's/.+("\[.+)/\1/' > $tmpfile.3 | |
# Change the position of the labels | |
cat $tmpfile.1 $tmpfile.3 $tmpfile.2 | | |
tr '\n\t' ',,' | # Replace line breaks and tabs with commas | |
sed 's/,$/\n/' # Repleace the last comma with a line break | |
my_exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The detail is in my blog article, which is written in Japanese.