Solved

Using extended grep to parse date string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best software for Unix commands in Windows cmd.exe? 18 102
Skill Development 15 163
unix solaris snoop command 6 85
Solaris 4.1.3 cloning and booting 13 72
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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

863 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

23 Experts available now in Live!

Get 1:1 Help Now