Solved

Using extended grep to parse date string

Posted on 2004-09-29
3
573 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now