Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to search/replace a bunch of text files in unix (osx)
    text
    copied!<p>I have a regular expression which I tested successfully on <a href="http://regexpal.com/" rel="nofollow">http://regexpal.com/</a> :</p> <pre><code>^(\".+?\"),\d.+?,"X",-99,-99,-99,-99,-99,-99,-99,(\d*),(\d*) </code></pre> <p>Where my test data looks like:</p> <pre><code>"AB101AA",10,"X",-99,-99,-99,-99,-99,-99,-99,394251,806376,179,"S00","SN9","00","QA","MH","X" "AB101AF",10,"X",-99,-99,-99,-99,-99,-99,-99,394181,806429,179,"S00","SN9","00","QA","MH","X" "AB101AG",10,"X",-99,-99,-99,-99,-99,-99,-99,394251,806376,179,"S00","SN9","00","QA","MH","X" "AB101AH",10,"X",-99,-99,-99,-99,-99,-99,-99,394371,806359,179,"S00","SN9","00","QA","MH","X" "AB101AJ",10,"X",-99,-99,-99,-99,-99,-99,-99,394171,806398,179,"S00","SN9","00","QA","MH","X" "AB101AL",10,"X",-99,-99,-99,-99,-99,-99,-99,394331,806530,179,"S00","SN9","00","QA","MH","X" </code></pre> <p>I want to replace it with <code>\1,\2,\3</code> on each line so for example line 1 would give</p> <pre><code>"AB101AA",394251,806376 </code></pre> <p>How can I run this regex search &amp; replace against all csv files in my folder in osx? I tried using sed but that complains with a syntax error (plus I'm unsure it will support this regex?). Additionaly, will the ^ (begining of line) and $ (end of line) anchors work line by line, or will they match the begin and end of the file?</p> <p>UPDATE: Some good responses with cut, awk ect that get specific fields from the csv, but I've recently learnt I need to take the numbers from that list and chop them into 2 sub-values, so my example output from above would need to look like:</p> <pre><code>"AB101AA",3,94251,8,06376 </code></pre> <p>As far as I know, I need to use a regex for this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload