Skip to main content
Fixed typo and quoting and now I can upvote
Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

This should work for bash:

for filename in *.fasta; do
  index=00$index="00${filename%_*}"
  addme=$addme="${index:((-3)):3}"
  sed "s/^>/>$addme-/g" 1_nc.fasta>$addme_tagged"$filename" > "$addme"_tagged.fasta
done

The trick was to expand the index to three-digit. Then you need " instead of ' to allow for expansion of $addme

This should work for bash:

for filename in *.fasta; do
  index=00${filename%_*}
  addme=${index:((-3)):3}
  sed "s/^>/>$addme-/g" 1_nc.fasta>$addme_tagged.fasta
done

The trick was to expand the index to three-digit. Then you need " instead of ' to allow for expansion of $addme

This should work for bash:

for filename in *.fasta; do
  index="00${filename%_*}"
  addme="${index:((-3)):3}"
  sed "s/^>/>$addme-/g" "$filename" > "$addme"_tagged.fasta
done

The trick was to expand the index to three-digit. Then you need " instead of ' to allow for expansion of $addme

Source Link
Philippos
  • 13.7k
  • 2
  • 42
  • 82

This should work for bash:

for filename in *.fasta; do
  index=00${filename%_*}
  addme=${index:((-3)):3}
  sed "s/^>/>$addme-/g" 1_nc.fasta>$addme_tagged.fasta
done

The trick was to expand the index to three-digit. Then you need " instead of ' to allow for expansion of $addme