Re: Extracting a variable listing

2010-08-18 Thread A. Wright

On Wed, 18 Aug 2010, Jack L. Stone wrote:


The content I need will always fall beneath a row of pound signs, and there
is content above that row I don't want, like this:

bunch of rows I don't need here
### --- the top of stuff needed
row1



If you want the '#' line in the output
cat YourFile | sed -n -e '/#/,$p'

If you don't, then
cat YourFile | sed -e '1,/#/d'

The above assumes that you will have at least 5 '#' chars on
your divider line, and never before in the file.  Increase the
number '#' symbols if the above example is strictly literal.
Note the -n in the first line.

A.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Extracting a variable listing

2010-08-18 Thread Jack L. Stone
At 10:53 AM 8.18.2010 -0300, A. Wright wrote:
On Wed, 18 Aug 2010, Jack L. Stone wrote:

 The content I need will always fall beneath a row of pound signs, and there
 is content above that row I don't want, like this:

 bunch of rows I don't need here
 ### --- the top of stuff needed
 row1


If you want the '#' line in the output
   cat YourFile | sed -n -e '/#/,$p'

If you don't, then
   cat YourFile | sed -e '1,/#/d'

The above assumes that you will have at least 5 '#' chars on
your divider line, and never before in the file.  Increase the
number '#' symbols if the above example is strictly literal.
Note the -n in the first line.

A.


Worked like a charm, Andrew! Just what I needed!

Jack

(^_^)
Happy trails,
Jack L. Stone

System Admin
Sage-american
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Extracting a variable listing

2010-08-18 Thread Matthias Apitz
El día Wednesday, August 18, 2010 a las 09:22:37AM -0500, Jack L. Stone 
escribió:

 At 10:53 AM 8.18.2010 -0300, A. Wright wrote:
 On Wed, 18 Aug 2010, Jack L. Stone wrote:
 
  The content I need will always fall beneath a row of pound signs, and there
  is content above that row I don't want, like this:
 
  bunch of rows I don't need here
  ### --- the top of stuff needed
  row1
 
 
 If you want the '#' line in the output
  cat YourFile | sed -n -e '/#/,$p'
 
 If you don't, then
  cat YourFile | sed -e '1,/#/d'
...

http://en.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat

:-)

matthias
-- 
Matthias Apitz
t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
e g...@unixarea.de - w http://www.unixarea.de/
Solidarity with the zionistic pirates of Israel?   Not in my  name!
¿Solidaridad con los piratas sionistas de Israel? ¡No en mi nombre!
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Extracting a variable listing

2010-08-18 Thread Dr. A. Haakh

Jack L. Stone schrieb:

Sorry to return to the trough again for script help, but find excellent
answers here when all else fails, and I am not very good at it.

Trying to develop a script (non-bash) that will extract a variable list of
content on a daily basis so I can add it to a master list. Once I have
this, I can do the rest of the scripting needed.

Here's an example of the need.

The content I need will always fall beneath a row of pound signs, and there
is content above that row I don't want, like this:

bunch of rows I don't need here
### --- the top of stuff needed
row1
row2
row3
row4
etc, etc

So, I need a way to pull out the rows (which vary daily) beneath the pound
row and place it in a new temp file that I can cat  into a master file.

Appreciate your kind help once again (beers on me!)

All the best!
Jack

(^_^)
Happy trails,
Jack L. Stone

System Admin
Sage-america

awk is your friend .-)
this script does exactly what you need
extract.awk
---
/^#+$/ {
   print $0;
   getline;
   print ,$0
   while (match($0, ^[[:print:]]+$)) {
   print $0;
   getline;
   }
}
---
You can still adjust the pattern in match to suit your need.
invoke it with
awk -f extract.awk yourfile

Andreas

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Extracting a variable listing

2010-08-18 Thread Dr. Andreas Haakh

Dr. A. Haakh schrieb:

Jack L. Stone schrieb:

Sorry to return to the trough again for script help, but find excellent
answers here when all else fails, and I am not very good at it.

Trying to develop a script (non-bash) that will extract a variable 
list of

content on a daily basis so I can add it to a master list. Once I have
this, I can do the rest of the scripting needed.

Here's an example of the need.

The content I need will always fall beneath a row of pound signs, and 
there

is content above that row I don't want, like this:

bunch of rows I don't need here
### --- the top of stuff needed
row1
row2
row3
row4
etc, etc

So, I need a way to pull out the rows (which vary daily) beneath the 
pound
row and place it in a new temp file that I can cat  into a master 
file.


Appreciate your kind help once again (beers on me!)

All the best!
Jack

(^_^)
Happy trails,
Jack L. Stone

System Admin
Sage-america

awk is your friend .-)
this script does exactly what you need
extract.awk
---
/^#+$/ {
   getline;
   while (match($0, ^[[:print:]]+$)) {
   print $0;
   getline;
   }
}
---
You can still adjust the pattern in match to suit your need.
invoke it with
awk -f extract.awk yourfile

Andreas

I forgot to remove some extra output :-)

--
Dr.-Ing. Andreas Haakh
Schwanengasse 13  *  64380 Roßdorf  *  andr...@haakh.de
Tel. 06154-694822 Fax. 06154-694821 Mobil 0173-361.6884

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Extracting a variable listing

2010-08-18 Thread Robert Bonomi

 Date: Wed, 18 Aug 2010 17:14:50 +0200
 From: Dr. A. Haakh bugrepor...@haakh.de
 Subject: Re: Extracting a variable listing

 Jack L. Stone schrieb:
 
  The content I need will always fall beneath a row of pound signs, and there
  is content above that row I don't want, like this:
 
  bunch of rows I don't need here
  ### --- the top of stuff needed
  row1
  row2
  row3
  row4
  etc, etc
 
 awk is your friend .-)
 this script does exactly what you need
 extract.awk
 ---
 /^#+$/ {
 print $0;
 getline;
 print ,$0
 while (match($0, ^[[:print:]]+$)) {
 print $0;
 getline;
 }
 }

**GAAACK**
let awk do the work for you

  BEGIN  { printing = 0 ; }
  printing==1{ print $0 ; }
  /^#+$/ { printing = 1 ; }

usage:  awk -f {thatfile} {datafile} {masterfile}
 
The BEGIN line is optional, and the '==1' is also un-necessary, but their
presecee makes the logic clearer for 'somebody else' that looks at it.


One can extract a block of lines from a file with the same logic.  just
add a pattern with an action of 'printing=0'.

If the 'printing=1' line is above the 'print $0' line, the start marker 
line will be included in the output, if below it won't show.

Similarly, if the 'printing=0' line is _below_ the 'print' line, the end
marker line will be included, if above it, it won't show.

The same basic approach trivially generalizes to extracting multiple blocks 
with different start/end markers, or to more complex markers -- e.g. trigger
criteria that involve multiple lines from the source file.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org