Advertisement
homer512

Match acronyms

Jun 20th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.56 KB | None | 0 0
  1. #/!bin/bash
  2.  
  3. # Example file containing acronyms
  4. acro_file=$(mktemp)
  5. printf "Foo\nBar\n" > "$acro_file"
  6.  
  7. # Example file containing server names
  8. server_file=$(mktemp)
  9. printf "FooServer\nBarServer\nBazServer\n" > "$server_file"
  10.  
  11. sed 's/\(.\{3\}\)/\1\t\1/' "$server_file" | # Prepend server names with first three characters and tab
  12. sort -k1 | # sort based on first column (i.e. acronym)
  13. join - <(sort "$acro_file") | # merge server_file and acro_file based on first column of both inputs
  14. cut -d' ' -f2 # keep only full server name
  15.  
  16. rm "$acro_file" "$server_file"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement