fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate: run in temp dir
  4. t=$(mktemp -d -t ideone.XXXXXXXX) || exit
  5. trap 'rm -rf "$t"' ERR EXIT
  6. cd "$t"
  7.  
  8. mkdir -p seq
  9.  
  10. cat <<\_ >seq/one.txt
  11. >first sequence
  12. aaaaaaaaa
  13. >second_sequence
  14. ccccccccc
  15. _
  16.  
  17. cat <<\_ >seq/two.txt
  18. >third sequence
  19. ggggggggg
  20. ggggggggg
  21. > fourth sequence
  22. tttttt
  23. tttttt
  24. _
  25.  
  26. echo "** OP's attempt"
  27.  
  28. awk 'BEGIN {RS=">"} {print $1}' seq/*.txt
  29. awk 'BEGIN {RS=">"} {print toupper ($2)}' seq/*.txt
  30.  
  31. echo '** Solution'
  32.  
  33. awk '/^>/ {
  34. if (n) printf "\n"
  35. n = 0
  36. sub(/>[[:space:]]*/, "")
  37. print >>"headers.txt"
  38. next
  39. }
  40. { printf("%s", toupper($1)); n=1 }
  41. END { if (n) printf "\n" }' seq/*.txt >sequences.txt
  42.  
  43. cat headers.txt sequences.txt
Success #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
** OP's attempt

first
second_sequence

third
fourth

SEQUENCE
CCCCCCCCC

SEQUENCE
SEQUENCE
** Solution
first sequence
second_sequence
third sequence
fourth sequence
AAAAAAAAA
CCCCCCCCC
GGGGGGGGGGGGGGGGGG
TTTTTTTTTTTT