 <p>This is a specific case of the general CSV parsing problem. The general solution is provided by Lorance Stinson (google <code>Stinson awk CSV parser</code>) but IMHO the simplest way to deal with this specific issue is to convert newlines within double quotes to some other character, do whatever you want with the file in single-line-per-record format, then convert back, e.g.:</p> <pre><code>$ cat file "Test_data1" "Test_data2" "1s" "452" "Test data643" " " "4d" "System" "Institute" "Test_data3" "Test_data4" "2s" "563" "Test data754" " " "5d" "Non System" "Association" </code></pre> <p>To convert to single line:</p> <pre><code>$ awk -v FS= '{for (i=1;i&lt;=NF;i++) if ($i=="\"") inQ=!inQ; ORS=(inQ?"♥":"\n") }1' file "Test_data1" "Test_data2" "1s" "452" "Test♥data643" "♥" "4d" "System" "Institute" "Test_data3" "Test_data4" "2s" "563" "Test♥data754" "♥" "5d" "Non System" "Association" </code></pre> <p>and to convert back is a simple <code>tr</code>:</p> <pre><code>$ awk -v FS= '{for (i=1;i&lt;=NF;i++) if ($i=="\"") inQ=!inQ; ORS=(inQ?"♥":"\n") }1' file | tr '♥' ' \n' "Test_data1" "Test_data2" "1s" "452" "Test data643" " " "4d" "System" "Institute" "Test_data3" "Test_data4" "2s" "563" "Test data754" " " "5d" "Non System" "Association" </code></pre> <p>The above uses control-C as a replacement for the newline within quotes, pick whatever character you like (or string if you want to use awk or sed rather than tr to convert back to newlines).</p> <p>Just insert the command to do whatever you want with your original file in between the awk and the tr, e.g. sort in reverse:</p> <pre><code>$ awk -v FS= '{for (i=1;i&lt;=NF;i++) if ($i=="\"") inQ=!inQ; ORS=(inQ?"♥":"\n") }1' file | sort -r | tr '♥' '\n' "Test_data3" "Test_data4" "2s" "563" "Test data754" " " "5d" "Non System" "Association" "Test_data1" "Test_data2" "1s" "452" "Test data643" " " "4d" "System" "Institute" </code></pre>