Hello,
Below command trims right after the nth occurrence of a string.
When I try in while loop
, it is not working.
In Terminal
IFS=/ ; read -ra val < Textfile ; echo "${val[*]:0:3}"
It gives only one line:
sunday/monday/tuesday
Textfile:
sunday/monday/tuesday/wednesday/thursday
august/feb/jan/april/
london/texas/paris/michigan/ontario
Expected output:
sunday/monday/tuesday
august/feb/jan
london/texas/paris
Script:
#!/bin/bash
while read -ra val
do
echo "${val[*]:0:3}"
done < Textfile
I could not solve this simple question.
Please let me know my fault.
Many thanks
Boris