开发者

gawk simple programs differences

开发者 https://www.devze.com 2023-02-13 18:52 出处:网络
Given the following input: SQSEQUENCE365 AA;40909 MW;78539C59DB8B1DFC CRC64; MAVMAPRTLV LLLSGALALT QTWAGSHSMR YFYTSVSRPG RGEPRFIAVG YVDDTQFVRF

Given the following input:

 SQ   SEQUENCE   365 AA;  40909 MW;  78539C59DB8B1DFC CRC64;
      MAVMAPRTLV LLLSGALALT QTWAGSHSMR YFYTSVSRPG RGEPRFIAVG YVDDTQFVRF
      DSDAASQRME PRAPWIEQEG PEYWDRNTRN VKAQSQTDRV DLGTLRGYYN QSEAGSHTIQ
      MMYGCDVGSD GRFLRGYRQD AYDGKDYIAL KEDLRSWTAA DMAAQTTKHK WEAAHVAEQW
      RAYLEGTCVE WLRRYLENGK ETLQRTDAPK THMTHHAVSD HEATLRCWAL SFYPAEITLT
      WQRDGEDQTQ DTELVETRPA GDGTFQKWVA VVVPSGQEQR YTCHVQHEGL PKPLTLRWEP
      SSQPTIPIVG IIAGLVLFGA VITGAVVAAV MWRRKSSDRK GGSYSQAASS DSAQGSDVSL
      TACKV

I need to join the lines which starts with 5 spaces. The following simple gawk commands first filters whit开发者_StackOverflow社区e-starting lines, and the other one strips out the white spaces, and it works as intended (I know there are many ways I can do this, I'm just learning gawk now):

gawk /^"     "/ input | gawk '{ gsub (" ", "", $0); print }'

My question is why, if I unite the two commands into one, it doesn't print anything. I'm sure it's a syntax issue somewhere:

gawk '/^"     "/ { gsub (" ", "", $0); print }' input


Take out the dbl-quote chars from your pattern in the 1 line version.

In a regular expression for patterns, every char is considered 'must be there', and as you have the whole of the command quoted in single-quotes, the shell will not strip away the double-quotes.

   gawk '/^     / { gsub (" ", "", $0); print }' input

(fyi: In unix text editing parlance, join usually is taken to mean, 'remove the carriage return, and have text continue on one line'. )

I hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消