Skip to content

Instantly share code, notes, and snippets.

@rtanikella
Last active November 9, 2018 17:35
Show Gist options
  • Save rtanikella/c4f5b8d8d6afe0e4cbb3851725456029 to your computer and use it in GitHub Desktop.
Save rtanikella/c4f5b8d8d6afe0e4cbb3851725456029 to your computer and use it in GitHub Desktop.
Adjust for a change in the article type of Classic Salesforce Knowledge Articles: This script adjusts the URLs of links within Classic Salesforce Knowledge Articles that reference other such articles to use an article type of 'Article' instead of 'Knowledge_Article_Type'
#!/bin/bash
if [ ! -n "$1" ]
then
multi_line_var=$( cat <<ENDxxx
Use this to adjust the URLs of links within Classic Salesforce Knowledge
Articles to use an article type of 'Article' instead of
'Knowledge_Article_Type'
Usage: KAT2A.sh input-file.csv
where input-file.csv is an extract of Classic Knowledge Articles from
Salesforce in the form of "Id","Article_content"
Script will
remove all line breaks (collapsing into a single line, outputting
intermediate temp file chomped.csv)
introduce line breaks ahead of head article Id (making the CSV one article
per line, outputting intermediate temp file one-per-line.csv)
replace all instances of /Knowledge_Article_Type/ with /Article/, writing
the final output to a new file entitled as Replaced-input-file.csv (the
input file name prefixed with 'Replaced-'.)
Once the final output is validated the chomped.csv, and one-per-line.csv can
be deleted.
ENDxxx
)
echo "$multi_line_var"
exit
fi
perl -pe "chomp;" "$1" > chomped.csv
perl -pe 's/"ka1/\n"ka1/sg;' chomped.csv > one-per-line.csv
perl -ne 'if($_ =~ s/\/Knowledge_Article_Type\//\/Article\//g){print;}' one-per-line.csv > "Replaced-$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment