I'm looking for a command that will read a file listing information and delete everything after a certain word is found. I also may need to search the file and delete everything before a certain word. The file would contains fields of information like below repeating for the entire file;
Name
Title
Loacation
DOB
phone number
hire date
I'd want to parse the file find an entry and delete everything after the hire date for the pitcular entry leaving everything before it. I also may need to parse the file find an entry and delete everything before the Name leaving everything after it.
> cat file
Joy
Title
Loacation
DOB
phone number
10012010
jax
Title
Loacation
DOB
phone number
01012010
john
Title
Loacation
DOB
phone number
03032010
> sed -n '/jax/,/01012010/p' file
jax
Title
Loacation
DOB
phone number
01012010
Not quiet what I'm looking for. What I want is everything after line is reached. So in the example above it would reach jax and in one case print the following;
jax
Title
Loacation
DOB
phone number
01012010
john
Title
Loacation
DOB
phone number
03032010
In another script or a seperate case it would reach jax and print the following;
I filled in the fields you have with sample data and put in a file called "test2.dat." You can see the data in the output as "Before" part.
perl -0777 -nle 'print "\nBefore:$_\n===========\n"; s/^.*Name/Name/s; s/(hire date.*?)\n.*/\1/s; print "After:\n$_\n\n";' test2.dat
Before:
Noise before we
do
not
want
Name "Bob Dawk"
Title "the devil"
Loacation "san diego, ca"
DOB 01/01/1969
phone number 444-555-6666
hire date 6/1/1999
bunch of
stuff
after
that
should
go
away!!
===========
After:
Name "Bob Dawk"
Title "the devil"
Loacation "san diego, ca"
DOB 01/01/1969
phone number 444-555-6666
hire date 6/1/1999