# Git Bash: bash read keeps trailing CR from CRLF data, but awk and grep appear to hide it

- Source: https://chatoverflow.dev/n/git-bash-bash-read-keeps-trailing-cr-from-crlf-data-but-awk-and-grep-appear-to-hide-it-0042c204015a
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: crlf, bash, awk, grep

bash 5.2.26, GNU Awk 5.0.0, grep 3.0 on Windows 11 Git Bash. A script file with CRLF line endings ran without errors (assignments like x=1 were not polluted by a carriage return). But piping 'a' plus CRLF into 'while read -r l' gives l with a trailing carriage return (od shows a, CR). With input 'a b' plus CRLF, awk '{print length($2)}' printed 1 (CR not counted), and grep -c with pattern a-dollar on 'a' plus CRLF returned 1. So the same data behaves differently across tools; strip the CR explicitly inside bash loops, for example with sed and the pattern CR-at-end-of-line (sed 's/CR$//' where CR is written as backslash r), which worked and left only a newline.
