Hi everyone!
I have a file like this
Medium label : R00034
Location : [RF-AUTOLOADER448-1: 6]
Medium Owner : so-rf5.inetrf
Status : Good
Blocks used [KB] : 310980608
Blocks total [KB] : 419430400
Usable space [KB] : 419430400
Number of writes : 2
Number of overwrites : 29
Number of errors : 0
Medium initialized : Thu Nov 9 18:31:29 2006
Last write : Sun Jan 10 01:06:04 2010
Last access : Mon Feb 15 18:27:04 2010
Last overwrite : Sun Jan 10 01:02:43 2010
Protected : None
Write-protected : No
Medium identifier : 0a347883:485109e2:10e3:0001
Medium label : R00061
Location : [RF-AUTOLOADER448-1: 1]
Medium Owner : so-rf5.inetrf
Status : Good
Blocks used [KB] : 113914688
Blocks total [KB] : 419430400
Usable space [KB] : 419430400
Number of writes : 2
Number of overwrites : 21
Number of errors : 0
Medium initialized : Thu Jun 12 13:34:58 2008
Last write : Thu Jan 14 23:08:36 2010
Last access : Mon Feb 22 09:06:01 2010
Last overwrite : Thu Jan 14 23:07:37 2010
Protected : None
Write-protected : No
Medium identifier : 0a347883:45597fda:4677:0001
Medium label : R00037
Location : [RF-AUTOLOADER448-1: 5]
Medium Owner : so-rf5.inetrf
Status : Good
Blocks used [KB] : 113839552
Blocks total [KB] : 419430400
Usable space [KB] : 419430400
Number of writes : 2
Number of overwrites : 3
Number of errors : 0
Medium initialized : Tue Nov 14 09:35:38 2006
Last write : Wed Jan 6 23:28:50 2010
Last access : Mon Feb 15 18:30:28 2010
Last overwrite : Wed Jan 6 23:27:46 2010
Protected : None
Write-protected : No
And I would like to find the Medium label when the value "last write" is "Jan 14" (it's could be another value like "jan 6")
I really don't know what way to use to solve this problem...
Thanks!
pattern="Jan 14"
awk -v pattern=$pattern ' /^Medium label/ {value=$0}
/^Last write/ && $0 ~ pattern { print} ' somefile > newfile
jim mcnamara solution tweaked as per OP requirement
awk -v pattern="$pattern" ' /^Medium label/ {value=$NF}
/^Last write/ && $0 ~ pattern { print value} ' somefile > newfile
Or:
awk '/Last write : Thu Jan 14/{print$4}' RS= infile
Could be easily adjusted to accept parameters.
anbu23
March 3, 2010, 10:07am
6
sed -n -e "/Medium label/{h;}" -e "/Last write.*Jan 14/{g;s/Medium label : //p;}" file