[opensuse] grep question
Hi all, I have files with mailing addresses in them. There are normally 4-5 lines with the first line starting with "address: " then the person's name and 3 or 4 more lines of address. Can (how) I use grep to pull all the address out? If not grep what else? Thanks! JIM -- Jim Hatridge Linux User #88484 Ebay ID: WartHogBulletin ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.WartHogBulletin.de Many Enemies -- Much Honor! Anti-US Propaganda stamp collection http://www.manyenemies-muchhonor.info An American in Bavaria http://www.gaubodengalerie.de -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 3/30/07, James Hatridge <James.Hatridge@gmx.de> wrote:
Hi all,
I have files with mailing addresses in them. There are normally 4-5 lines with the first line starting with "address: " then the person's name and 3 or 4 more lines of address. Can (how) I use grep to pull all the address out? If not grep what else?
I don't think grep can handle variable multiline results. I would attack it with awk. (or gawk). It is a pretty flexible reporting package. Ignoring syntax a control file like: START {print_lines=0; echo "File Header" > "output_file" } /address:/ {print_lines=4} {print_lines = print_lines-1 if (print_lines > 0) print $0 >> "output_file" } should be the basic code. Then invoke it with: awk -f control_file * FYI: Double check all the above, but it should be enough to point you in the right direction. Greg -- Greg Freemyer The Norcross Group Forensics for the 21st Century -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 30 March 2007 15:47, James Hatridge wrote:
Hi all,
I have files with mailing addresses in them. There are normally 4-5 lines with the first line starting with "address: " then the person's name and 3 or 4 more lines of address. Can (how) I use grep to pull all the address out? If not grep what else?
grep -A 4 name file perhaps? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi all! On Friday 30 March 2007 18:53, Anders Johansson wrote:
On Friday 30 March 2007 15:47, James Hatridge wrote:
Hi all,
I have files with mailing addresses in them. There are normally 4-5 lines with the first line starting with "address: " then the person's name and 3 or 4 more lines of address. Can (how) I use grep to pull all the address out? If not grep what else?
grep -A 4 name file
Thanks to Anders and all the others that sent me a clue! Anders' idea worked fine and very simple. Thanks! JIM -- Jim Hatridge Linux User #88484 Ebay ID: WartHogBulletin ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.WartHogBulletin.de Many Enemies -- Much Honor! Anti-US Propaganda stamp collection http://www.manyenemies-muchhonor.info An American in Bavaria http://www.gaubodengalerie.de -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
James, On Friday 30 March 2007 06:47, James Hatridge wrote:
Hi all,
I have files with mailing addresses in them. There are normally 4-5 lines with the first line starting with "address: " then the person's name and 3 or 4 more lines of address. Can (how) I use grep to pull all the address out? If not grep what else?
Find and install "agrep". It can process multi-line records. The "a" stands for "approximate" and it can do much more sophisticated matching than the stock grep family can. I found version 4.0 of the package "agrep" in the Packman RPM repository.
Thanks!
JIM -- Jim Hatridge
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (4)
-
Anders Johansson
-
Greg Freemyer
-
James Hatridge
-
Randall R Schulz