I have a file.txt and each line of the file is like:
ABLED EY B AH L D
ABLER EY B AH L ER
I want to have the second part of each line: EY B AH L D
or EY B AH L ER
, for example, in lower case, keeping the rest upper case. How can I do it?
Thank you very much in advance.
while read first second; do
second=$(echo "$second" | tr [:upper:] [:lower:])
printf '%s\t%s\n' "$first" "$second"
done < file.txt
Output:
ABLED ey b ah l d
ABLER ey b ah l er
Two other ways to do it in KornShell, pdksh, or Bash without calling tr
set the "lowercase" flag on the variable (KornShell and compatible shells only):
typeset -l second
while read first second; do
printf '%s\t%s\n' "$first" "$second"
done < file.txt
use Bash's case-modification parameter expansion modifier (Bash only!):
while read first second; do
printf '%s\t%s\n' "$first" "${second,,}"
done < file.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With