Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save huynhbaoan/c09ec4e9b2f7dc0b626bb3c6cba105cc to your computer and use it in GitHub Desktop.
Save huynhbaoan/c09ec4e9b2f7dc0b626bb3c6cba105cc to your computer and use it in GitHub Desktop.
while IFS= read -r line; do
# Check if the line contains a tab
if [[ "$line" == *$'\t'* ]]; then
# Split the line by tabs into an array
IFS=$'\t' read -r -a cols <<< "$line"
# Only process if at least 4 columns exist
if [[ ${#cols[@]} -ge 4 ]]; then
# Grab column 4
col4="${cols[3]}"
# Do the replacements using perl
col5=$(perl -pe 's/-private|-tooling|-v[0-9]+(secondary)?//g' <<< "$col4")
# Output original columns plus new column 5
printf "%s\t%s\n" "$line" "$col5"
else
echo "$line"
fi
else
echo "$line"
fi
done < yourfile.tsv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment