Reformat file, tricky.

Reformat file, tricky.

Post by David Kenne » Wed, 21 Jan 1998 04:00:00



I have a file (actually a very long*log) which I'd like to
clean up for viewing, via a small script for use when I get an
error.

The file has lines like this scattered through it:
[12] [13] [14] [15
]                    
[17
]    
[33
] [34]  

Can anyone deeply versed in the ways of sed or similar
provide a method of coping with this to produce

[12] [13] [14] [15]
[17]
[33] [34]

Or, second choice, a way of deleting any line with just [ ] or numerals.

Thanks in advance.

--
David Kennedy, Dept. of Pure & Applied Physics, Queen's University of Belfast

               My .sig was so clever that it actually escaped!

 
 
 

Reformat file, tricky.

Post by Justin Bank » Wed, 21 Jan 1998 04:00:00



> I have a file (actually a very long*log) which I'd like to
> clean up for viewing, via a small script for use when I get an
> error.

> The file has lines like this scattered through it:
> [12] [13] [14] [15
> ]                    
> [17
> ]    
> [33
> ] [34]  

> Can anyone deeply versed in the ways of sed or similar
> provide a method of coping with this to produce

> [12] [13] [14] [15]
> [17]
> [33] [34]

I don't know the particulars of your case, but try this :

#!/opt/local/bin/perl5

use Getopt::Std;
getopt(fo);

($opt_f && $opt_o) || die "Usage : $0 -f <infile> -o <outfile>";
open DFILE, "$opt_f" || die "Can't open input file : $!";
open OFILE, ">$opt_o" || die "Can't open output file : $!";

while(<DFILE>) {
 if($_ =~ /^]\s+$/) {
  print OFILE;
 }
 else {
  chop;  # newline
  chop;  # space
  print OFILE;
 }

Quote:}

close OFILE;
close DFILE;
exit 0;

-justinb
--
Justin Banks     \ if the answer is the same whether you're programming
Silicon Graphics \ in Perl, C, or Visual Modula 17++ with JavaBeans and
Eagan, Minnesota \ Digital Satellite TV Support, it's not a Perl question.
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq' | dc

 
 
 

Reformat file, tricky.

Post by James Youngma » Wed, 21 Jan 1998 04:00:00


  David> I have a file (actually a very long*log) which I'd like to
  David> clean up for viewing, via a small script for use when I get an
  David> error.

  David> The file has lines like this scattered through it:
  David> [12] [13] [14] [15
  David> ]                    
  David> [17
  David> ]    
  David> [33
  David> ] [34]  

  David> Can anyone deeply versed in the ways of sed or similar
  David> provide a method of coping with this to produce

  David> [12] [13] [14] [15]
  David> [17]
  David> [33] [34]

  David> Or, second choice, a way of deleting any line with just [ ]
  David> or numerals.

I'm not sure what you want as the condition for ending lines, but what
about passing it through the filter

  ... | tr -d '\012' | fmt -s | ......

 
 
 

1. Tricky SED matching and replace pattern for reformatting source codes brackets

Ok, I know, the recommended bracket style for source codes (e.g. in java) is like:

   if (.....)
   {
      command statements
   }

But all the curly brackets at the beginning is for me rather bugging and makes me nervous.
I prefer a style like

   if (.....) {
      command statements }

where different nesting levels are visualized by different indention.
I don't want to discuss this style at this place.

However I need a good sed search and replace pattern which converts a source code file with old
curly bracketing into my personal style.

This should be theoretically rather easy. I only need a pattern which replaces

   blank-blank-curlybracket

   or

   controlreturn-blank-curlybracket

   or

   controlreturn-curlybracket

   into

   blank-curlybracket

iteratively as often as necessary for the whole file.
Notice that before a closing curly bracket there should be exactly one blank.

I feel that this is somehow feasible with sed but I cannot find the magic pattern.

Can someone help me?

Matt

2. New kernel 2.2.0 and ICMP ?

3. Reformatting a file

4. Basic question about PCI device drivers

5. what is fastest way to reformat file from variable to fixed length

6. ???Win98 and SAMBA question

7. reformatting directory files

8. Top 10 posters comp.unix.admin

9. Help Needed to Reformat a File

10. Sed Question - File Reformat

11. Reformatting file before ftp transfer

12. REALLY tricky question: different files depending on system

13. tricky file script