fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate - we can't write files in the home directory;
  4. # so create a temporary directory for our files instead
  5. t=$(mktemp -d -t ideone.XXXXXXXXXXXX) || exit
  6. trap 'rm -rf "$t"' ERR EXIT
  7. cd "$t"
  8.  
  9.  
  10. cat <<\_ >gene_list
  11. ccl5
  12. cxcr4
  13. setx
  14. _
  15.  
  16. tr , '\t' <<\_ >original_file.txt
  17. ccl4,3,18000,50000
  18. ccl5,4,400,5000
  19. cxcr4,5,300,2500
  20. apoe,4,100,90
  21. setx,3,200,1903
  22. _
  23.  
  24.  
  25. awk -F '\t' ' FILENAME=="gene_list" {arr[$1]; next}
  26. $1 in arr { x=sprintf("%1.0f", $3-($4/10)); if (x<0) x=0; print $1, $2, x, $4; next }
  27. 1' gene_list original_file.txt
Success #stdin #stdout 0.01s 5628KB
stdin
Standard input is empty
stdout
ccl4	3	18000	50000
ccl5 4 0 5000
cxcr4 5 50 2500
apoe	4	100	90
setx 3 10 1903