Skip to content

Commit

Permalink
use tmp files
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillanacosta committed Jul 17, 2024
1 parent 66de9e3 commit f409b74
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/chebi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,32 @@ jobs:
added=$(grep '^+CHEBI' "$output_file" | sed 's/-//g') || true
# retrieve removed lines
removed=$(grep '^-' "$output_file" | sed 's/-//g') || true
# retrieve withdrawn IDs
withdrawn=$(echo "$added" | grep 'Entry Withdrawn') || true
# Create temporary files
tmp_added=$(mktemp)
tmp_withdrawn=$(mktemp)
tmp_removed=$(mktemp)
# Write the content of the added variable to the temporary file
echo "$added" > "$tmp_added"
# Retrieve matches and store them in another temporary file
grep 'Entry Withdrawn' "$tmp_added" > "$tmp_withdrawn" || true
# Append matches to the removed variable
if [ -n "$removed" ]; then
removed="${removed}"$'\n'"${withdrawn}"
echo -e "$removed\n$(cat $tmp_withdrawn)" > "$tmp_removed"
else
removed="${withdrawn}"
cat "$tmp_withdrawn" > "$tmp_removed"
fi
# Remove matching lines from the added variable
sed '/Entry Withdrawn/d' "$tmp_added" > "$tmp_added.tmp" && mv "$tmp_added.tmp" "$tmp_added"
# Read the updated content back into the variables
added=$(cat "$tmp_added")
removed=$(cat "$tmp_removed")
# Clean up temporary files
rm "$tmp_added" "$tmp_withdrawn" "$tmp_removed"
added=$(echo "$added" | sed '/Entry Withdrawn/d')
added_filtered=$(comm -23 <(sort <<< "$added") <(sort <<< "$removed"))
removed_filtered=$(comm -23 <(sort <<< "$removed") <(sort <<< "$added"))
Expand Down

0 comments on commit f409b74

Please sign in to comment.