From: moonhkt on 13 Jul 2010 02:32 Hi All How to grep multi-line, when input particlar date ? Text file 2010/06/21 Canon Scanner 9000F 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 S/N etc... 2010/07/06 Mail Rebate Form to MAC Apple, http://www.apple.com/hk/promo/rebate/bts.html input 2010/06/30 return following line ? Under date string may be more than one line. This example return 3 lines. 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 S/N etc... moonhkt
From: Janis Papanagnou on 13 Jul 2010 04:45 moonhkt schrieb: > Hi All > > How to grep multi-line, when input particlar date ? > > Text file > 2010/06/21 Canon Scanner 9000F > 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 > S/N > etc... > 2010/07/06 Mail Rebate Form to MAC Apple, http://www.apple.com/hk/promo/rebate/bts.html > > input 2010/06/30 return following line ? Under date string may be > more than one line. This example return 3 lines. > 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 > S/N > etc... > > moonhkt One approach is awk -v d="$1" '(!/^ / && f=($1~d)) || (f && /^ /)' Janis
From: Ed Morton on 13 Jul 2010 07:53 On 7/13/2010 1:32 AM, moonhkt wrote: > Hi All > > How to grep multi-line, when input particlar date ? > > Text file > 2010/06/21 Canon Scanner 9000F > 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 > S/N > etc... > 2010/07/06 Mail Rebate Form to MAC Apple, http://www.apple.com/hk/promo/rebate/bts.html > > input 2010/06/30 return following line ? Under date string may be > more than one line. This example return 3 lines. > 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 > S/N > etc... > > moonhkt Try this (untested): awk -v d="2010/07/06" '$0 ~ /^[[:digit:]]/ {f = ($1 == d)} f' file Ed.
From: Ben Bacarisse on 13 Jul 2010 09:13 Ed Morton <mortonspam(a)gmail.com> writes: > On 7/13/2010 1:32 AM, moonhkt wrote: >> How to grep multi-line, when input particlar date ? >> >> Text file >> 2010/06/21 Canon Scanner 9000F >> 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 >> S/N >> etc... >> 2010/07/06 Mail Rebate Form to MAC Apple, http://www.apple.com/hk/promo/rebate/bts.html <snip> > Try this (untested): > > awk -v d="2010/07/06" '$0 ~ /^[[:digit:]]/ {f = ($1 == d)} f' file Is there a reason to prefer "$0 ~ /^[[:digit:]]/" over the simpler "/^[[:digit:]]/" as the pattern? -- Ben.
From: Ed Morton on 13 Jul 2010 12:17 On 7/13/2010 8:13 AM, Ben Bacarisse wrote: > Ed Morton<mortonspam(a)gmail.com> writes: > >> On 7/13/2010 1:32 AM, moonhkt wrote: >>> How to grep multi-line, when input particlar date ? >>> >>> Text file >>> 2010/06/21 Canon Scanner 9000F >>> 2010/06/30 MacBook Pro Delivery, Original 2010/07/02 >>> S/N >>> etc... >>> 2010/07/06 Mail Rebate Form to MAC Apple, http://www.apple.com/hk/promo/rebate/bts.html > <snip> >> Try this (untested): >> >> awk -v d="2010/07/06" '$0 ~ /^[[:digit:]]/ {f = ($1 == d)} f' file > > Is there a reason to prefer "$0 ~ /^[[:digit:]]/" over the simpler > "/^[[:digit:]]/" as the pattern? > No, that's just what happens when you start off thinking $1 ~ ... then realise $0 is at least as appropriate. Ed.
|
Next
|
Last
Pages: 1 2 3 4 Prev: STAND CLEAR of LEW PITCHER!!! Next: Make Money $100 to $200 Daily Online |