Created
November 25, 2019 08:08
-
-
Save sipadan2003/6e1bdfc7564c1ebdf4cd649df7799936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
p001(){ | |
local input1=$1 | |
local input2=$2 | |
local output=$3 | |
local pattern="^\([0-9]\+\)[ ]\+\([A-Za-z]\+\)$" | |
declare -A array | |
for i in `grep -E "^[0-9]+[ ]+[A-Za-z]+$" $input2` | |
do | |
local k=`echo "$i" | sed -e "s/$pattern/\1/g"` | |
local v=`echo "$i" | sed -e "s/$pattern/\2/g"` | |
array["$k"]="$v" | |
done | |
rm -f $output | |
cat $input1 | while read line | |
do | |
local k=`echo "$line" | sed -e "s/^\(r_\)\([0-9]\+\)\(:.\+\)$/\2/g"` | |
if [ -n "${array[$k]}" ]; then | |
local n=`echo "$line" | sed -e "s/^\(r_\)\([0-9]\+\)\(:.\+\)$/\1${array[$k]}\3/g"` | |
echo $n >> $output | |
fi | |
done | |
} | |
p001 test01.txt test02.txt output.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment