Solved

Using extended grep to parse date string

Posted on 2004-09-29
3
576 Views
Last Modified: 2008-03-03
I have the following data in text file.

Christopher Robin|boy|birthday cake|11/2/1975
Eeyore|donkey|thistles|7/10/1865
Heffalump|scary elephant|honey|6/30/2004
Kanga|kangaroo|alphabet soup|2/22/1922
Owl|bird|small rodents|1/1/2000
Piglet|small pig|hay corns|4/47/1945
Pooh|bear|honey|5/14/1942
Rabbit|bunny rabbit|vegetables|3/5/2004
Roo|joey|apples|8/1/1950
Tigger|tiger|mud|1/1/2000
Woozle|flying bee-elephant|honey|9/12/2004


I need to print just the characters birth year for the middle five linesand then append to another file.  
This would be lines Kanga thru Rabbit.  

I have accomplished this much:

 head -8 aamilne.sorted | tail -5 | awk -F"|" '{print $4}'  > TEST2

this code gives me:

2/22/1922
1/1/2000
4/47/1945
5/14/1942
3/5/2004

Now I only need the year, I have used several grep commands and cannot fiqure it out.  I know that I have to extended grep.  I have used:
 grep -E '$[0-9]+'
 grep -E $[0-9] TEST2 |cut -c4-c8
 grep -E $'[4,9]' TEST2

These are just a few, could someone please help.  Yes this is a lab problem.

Thanks


0
Comment
Question by:dabrat
3 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 12186755
which year you want, you can grep the year and then cut it out

cat TEST2 |  cut -f3 -d"/"

will output the years!
0
 
LVL 40

Accepted Solution

by:
jlevie earned 50 total points
ID: 12186757
head -8 aamilne.sorted | tail -5 |  sed -e "s/.*\/\([0-9]*$\)/\1/"

Will do it in one command.
0
 
LVL 1

Author Comment

by:dabrat
ID: 12186785
Thank you, I did not to do it in one command!

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question