I am trying to grep the specific pattern /home/mytest/data from each line of 1.txt file and when the match is found then copy the complete line to 2.txt file. But result set in 2.txt file is not the expected result.
Code
i=/home/mytest/data
IFS=',' read -ra ADDR <<< "$File_Name"
Input=1.txt
for i in "${ADDR[@]}";
do
j=0
while IFS= read -r line;
do
j=$((j+1))
Exists=$(echo $line | grep -w "$i" )
if [[ ! -z "$Exists" ]]; then
cp=$(echo $line >> 2.txt)
fi
done <"$Input"
Expected Result - 2.txt
# file: /home/mytest/data # owner: own # group: group-sm user::r-x group::rwx mask::rwx other::--- default:user::rwx default:group::r-x default:group:smr:rwx default:group:agm:r-x default:mask::rwx default:other::---
Actual Result - 2.txt
# file: /home/mytest/data # owner: own # group: group-sm user::r-x group::rwx mask::rwx other::--- default:user::rwx default:group::r-x default:group:smr:rwx default:group:agm:r-x default:mask::rwx default:other::---
# file: /home/mytest/datasr123 # owner: own # group: group-sm user::r-x group::rwx mask::rwx other::---
Grep version: GNU grep 2.20
grepare you using?grep --version?