Im stuck here. Not sure why my reg ex won’t work. I have a pipe delimited text file with a series of columns. I need to extract the 3rd column.
File:
A|B|C|D|E|F|G|H|I
2011-03-03 00:00:00.0|1|60510271|254735|27751|BBB|1|-0.1619023623|-0.009865904
2011-03-03 00:00:00.0|1|60510270|254735|27751|B|3|-0.0064786612|-0.0063739185
2011-03-03 00:00:00.0|1|60510269|254735|27751|B|3|-0.0084998226|-0.009244384
Regular expression:
$> head foo | perl -pi -e 's/^(.*)\|(.*)\|(.*)\|(.*)$/$3/g'
Output
-0.1619023623
-0.0064786612
-0.0084998226
Clearly not the correct column being outputted.
Thoughts ?
You need to make your pattern greedy – so:
's/^(.*?)\|(.*?)\|(.*?)\|(.*)$/$3/g'