Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. Y15-SUB-B04-P17-BK_M02734_4_000000000-ANNUF_1_1111_24724_4878;size=1;
  2. Y15-SUB-B05-P22-LM_M02734_4_000000000-ANNUF_1_1111_20624_14973;size=1;
  3. Y15-SUB-B05-P22-LM_M02734_4_000000000-ANNUF_1_1103_11326_10379;size=1;
  4.  
  5. Y15-SUB-B04-P17-BK_M02734:4:000000000-ANNUF:1:1111:24724:4878;size=1;
  6. Y15-SUB-B05-P22-LM_M02734:4:000000000-ANNUF:1:1111:20624:14973;size=1;
  7. Y15-SUB-B05-P22-LM_M02734:4:000000000-ANNUF:1:1103:11326:10379;size=1;
  8.  
  9. sed 's/_/:/2' old_file > new_file
  10.  
  11. sed -i'' 's/_/:/2g' file
  12.  
  13. cat script.awk
  14. match($0,/^[^_]*_/,a){ # match current line to first _ (including) into a[0] variable
  15. sub(a[0],""); # remove a[0] from current line
  16. gsub("_",":"); # replace all _ to : in current line
  17. print a[0]""$0; # ouput a[0] and current line
  18. }
  19.  
  20. awk -f script.awk input.txt
  21.  
  22. awk 'match($0,/^[^_]*_/,a){sub(a[0],"");gsub("_",":");print a[0]""$0;}' input.txt
  23.  
  24. <field 1>_<field 2>:<field n>:<field n+1>:...
  25.  
  26. awk -F_ '{ printf("%s_%s", $1, $2); for (x = 3; x <=NF; x++) { printf(":%s", $x); }; printf("n"); }'
  27.  
  28. awk -F_ '{printf("%s_%s:%s:%s:%s:%s:%s:%sn", $1, $2, $3, $4, $5, $6, $7, $8);}'
  29.  
  30. Y15-SUB-B04-P17-BK_M02734:4:000000000-ANNUF:1:1111:24724:4878;size=1;
  31. Y15-SUB-B05-P22-LM_M02734:4:000000000-ANNUF:1:1111:20624:14973;size=1;
  32. Y15-SUB-B05-P22-LM_M02734:4:000000000-ANNUF:1:1103:11326:10379;size=1;
  33.  
  34. sed -i "s/_/:/2g" filename
  35.  
  36. perl -pe '{$n=0}s{_}{++$n > 1 ? ":" : $&;}ge' file
  37.  
  38. $ sed -e '
  39. y/_/n/
  40. s/n/_/
  41. y/n/:/
  42. ' inp.file
  43.  
  44.  
  45. $ perl -pe '1 while s/_.*?K_/:/g' inp.file
  46.  
  47. #include <stdio.h>
  48. #include <string.h>
  49. int main ( int argc, char *argv[] ) {
  50. FILE *infp = (argc>1? fopen(argv[1],"r") : stdin ),
  51. *outfp = (argc>2? fopen(argv[2],"w") : stdout );
  52. char line[9999], *lptr=line, this = '_', that = ':';
  53. int nskip = 1, nfound = 0;
  54. if ( infp != NULL && outfp != NULL ) {
  55. while ( (lptr=fgets(line,9990,infp)) != NULL ) {
  56. nfound = 0;
  57. while ( (lptr=strchr(lptr,this)) != NULL ) {
  58. if ( ++nfound > nskip ) *lptr = that;
  59. lptr++; }
  60. if ( fputs(line,outfp) == EOF ) break;
  61. } /* --- end-of-while(fgets()!=NULL) --- */
  62. if ( infp != stdin ) fclose(infp);
  63. if ( outfp != stdout ) fclose(outfp);
  64. } /* --- end-of-if(in,outfp!=NULL) --- */
  65. } /* --- end-of-function main() --- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement