-1

Here is a sample record from a data file

Ram|2015-03-01|204012|||inact|2014-02-01|

There are hundreds of such records. I want to retrieve the first date field from the first record. I tried using grep but it prints the entire line.

Output should be:

2015-03-01
chiwangc
  • 3,566
  • 16
  • 26
  • 32

1 Answers1

0

Check out the --only-matching option in the Grep Man page. You'll have to rewrite your regex to match the first two fields, then use grep again to get the date field. E.g. grep --only-matching [regex for first two fields] | grep --only-matching [regex for date field].

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
  • I'm not going to write the solution for you. I can at best help you fix your problem. But to do that You've to tell me how to reproduce the problem. See http://stackoverflow.com/help/how-to-asky – M.P. Korstanje May 17 '15 at 08:56