Lets say I have a csv file like this:
a,b1,12, a,b1,42, d,e1,12, r,12,33,
I want to use grep to return only only the rows where the third column = 12. So it would return:
a,b1,12, d,e1,12,
but not:
r,12,33,
Any ideas for a regular expression that will allow me to do this?
The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.
If you already have Microsoft Excel installed, just double-click a CSV file to open it in Excel. After double-clicking the file, you may see a prompt asking which program you want to open it with. Select Microsoft Excel. If you are already in Microsoft Excel, you can choose File > Open and select the CSV file.
The GREP command - an overviewBy default, grep displays the matched lines, and it can be used to search for lines of text that match one or more regular expressions, and it outputs only the matched lines.
I'd jump straight to awk to test the value exactly
awk -F, '$3 == 12' file.csv
This, and any regexp-based solution, assumes that the values of the first two fields do not contain commas
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