I am trying to edit some files using regular expressions.
sed
seemed too limited so I switched to Perl.
There might be something wrong in my syntax.
The regex pattern works in TextMate.
Nothing happens when I use Perl.
I want to remove all lines not containing SourceFile
or ""
.
For your information, it's for cleaning up output data from exiftools
.
$ perl -pe 's/^(?!.*(SourceFile|"").*).*$\n//g' out.csv
$ cat out.csv
SourceFile,GPSLatitude,GPSLongitude
1.jpg,,
2.jpg,,
3.jpg,"10 deg 20' 30.30"" N","40 deg 50' 60.60"" W"
4.jpg,"10 deg 20' 30.30"" N","40 deg 50' 60.60"" W"
The clean up should keep the first line and all lines containing GPS data. So after clean up it should look like:
SourceFile,GPSLatitude,GPSLongitude
3.jpg,"10 deg 20' 30.30"" N","40 deg 50' 60.60"" W"
4.jpg,"10 deg 20' 30.30"" N","40 deg 50' 60.60"" W"