Solved

Using extended grep to parse date string

Posted on 2004-09-29
3
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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 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.:
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…

728 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