Guest User

Untitled

a guest
Feb 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. abc:123:myname:1231
  2. def:423324:arbitrary:value:string
  3. StackExchange:Unix:Linux
  4.  
  5. #!/bin/bash
  6. key_word_I_am_looking_for=$1
  7. my_variable=`cat myfile.csv | awk -F: -v keyword="$key_word_I_am_looking_for" '( $1 == keyword )' END{print "$@" }'`
  8. echo "$my_variable"
  9.  
  10. #!/bin/bash
  11. awk -F: -v keyword="$1" '$1 == keyword {$1=$1; print}' myfile.csv
  12.  
  13. grep "^$1:" myfile.csv | tr ":" " "
  14.  
  15. sed -n '/^def:/s/:/ /gp' myfile.csv
  16.  
  17. sed -n "/^$1:/s/:/ /gp" myfile.csv
  18.  
  19. $ python -c "import sys;
  20. with open(sys.argv[2]) as f:
  21. for line in f:
  22. if sys.argv[1] == line.split(':')[0]:
  23. print ' '.join(line.strip().split(':'))" def file
  24. def 423324 arbitrary value string
Add Comment
Please, Sign In to add comment