Reformatting a csv file, script is confused by ' %." ' <p>I'm using bash on cygwin.</p> <p>I have to take a .csv file that is a subset of a much larger set of settings and shuffle the new csv settings (same keys, different values) into the 1000-plus-line original, making a new .json file. </p> <p>I have put together a script to automate this. The first step in the process is to "clean up" the csv file by extracting lines that start with "mme " and "sms ". Everything else is to pass through cleanly to the "clean" .csv file.</p> <p>This routine is as follows:</p> <pre><code># clean up the settings, throwing out mme and sms entries cat extract.csv | while read -r LINE; do if [[ $LINE == "mme "* ]] then printf "$LINE\n" &gt;&gt; mme_settings.csv elif [[ $LINE == "sms "* ]] then printf "$LINE\n" &gt;&gt; sms_settings.csv else printf "$LINE\n" &gt;&gt; extract_clean.csv fi done </code></pre> <p>My problem is that this thing stubs its toe on the following string at the end of one entry: <code> 100%."</code> When it's done with the line, it simply elides the <code>%."</code> and the new-line marker following it, and smears the two lines together:</p> <pre><code>... 100next.entry.keyname... </code></pre> <p>I would love to reach in and simply manually delimit the <code>%</code> sign, but it's not a realistic option for my use case. Clearly I'm missing something. My suspicion is that I am in some wise abusing <code>cat</code> or <code>read</code> in the first line. </p> <p>If there is some place I should have looked to find the answer before bugging you all, by all means point me in that direction and I'll sod off.</p>