Created
January 30, 2020 05:19
-
-
Save sipadan2003/1158a903e08c12a77bed362770aac4c6 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 | |
printUsage() { | |
echo "Usage: reem006 <input-file> <line-number>" | |
exit 1 | |
} | |
compareArray() { | |
local counter=$1 | |
if [ ${#TARGET_LINE[@]} != ${#TMP_LINE[@]} ]; then | |
return | |
fi | |
for ((i=0; i < ${#TARGET_LINE[@]}; i++)); do | |
local c1=${TARGET_LINE[i]} | |
local c2=${TMP_LINE[i]} | |
if [ -n "$c1" ] && [ -z "$c2" ]; then | |
return | |
elif [ -z "$c1" ] && [ -n "$c2" ]; then | |
return | |
fi | |
done | |
printf "%06d\n" ${counter} | |
} | |
getTargetLine() { | |
local counter=0 | |
local IFS= | |
while read row; do | |
if [ "$2" == "${counter}" ]; then | |
echo ${row} | tr '\t' '\n' > tmp.txt | |
while read column; do | |
TARGET_LINE+=("${column}") | |
done < "tmp.txt" | |
return | |
fi | |
let counter=${counter}+1 | |
done < "$1" | |
} | |
readLines() { | |
local counter=0 | |
local IFS= | |
while read row; do | |
if [ ${counter} -eq 0 ]; then | |
: | |
elif [ ${counter} -eq $2 ]; then | |
: | |
else | |
echo ${row} | tr '\t' '\n' > tmp.txt | |
TMP_LINE=() | |
while read column; do | |
TMP_LINE+=("${column}") | |
done < "tmp.txt" | |
compareArray ${counter} | |
fi | |
let counter=${counter}+1 | |
done < "$1" | |
} | |
if [ $# -ne 2 ]; then | |
printUsage | |
fi | |
declare -a TARGET_LINE=() | |
declare -a TMP_LINE=() | |
getTargetLine $1 $2 | |
readLines $1 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment