The following code will output:
Line: 2023-06-29 14:57:45 (62.3 MB/s) - ‘www.bharatbenz.com/sales-enquiry/index.html?1015R+ - 10 ?? ?????? ?????? ???? ?? ????? | ???????? ????-VI BS-VI ????.html’ saved [112171/112171]
Array: 2023-06-29 14:57:45 (62.3 MB/s) - ‘www.bharatbenz.com/sales-enquiry/index.html?1015R+ - 10 ?? ?????? ?????? ???? ?? ????? | uniq.txt ????-VI BS-VI ????.html’ saved [112171/112171]
the echo "Line:" $line
outputs the correct string. But once you add it to the array and echo the array echo "Array:" ${savedUrlLines[@]}
it has added uniq.txt
into the string, which is a file in the local directory. If I move the script and run it in another directory then file names from that local directory will appear in the output, why?
Running on Ubuntu 20.04.5 LTS
Thanks
#!/bin/bash
savedUrlsFile=$(cat log.txt | awk '/saved/ {print $0}')
savedUrlLines=()
OLDIFS=$IFS
IFS=$'\n'
for line in $savedUrlsFile
do
if [[ $(echo $line | grep 14:57:45) != '' ]]; then
echo "Line:" $line
savedUrlLines+=($line)
fi
done
IFS=$OLDIFS
echo
echo "Array:" ${savedUrlLines[@]}