Solved

Using extended grep to parse date string

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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
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.

732 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