0

This is similar to

Linux GREP/SED [xargs] find pattern and line number in files and remove with SED

How to change all occurrences of a word in all files in a directory

but I am having problems applying these with \n.

I am trying to remove all comments (// and /**/) and all newline characters, then insert a newline after each } and }; from a function. I also need precompiler directives to be ignored.

This is all to the ends that each include, define, struct, and function to be on its own line for some aggregation into a single file.--I'm refactoring a large project.

Community
  • 1
  • 1
Josh
  • 295
  • 1
  • 9
  • 3
    "having problems" is not an error. How can you expect help if you don't say what you did and what the problem is? – stark May 10 '12 at 02:37
  • The problem is that I don't know exactly how to do what I'm trying to do. – Josh May 10 '12 at 02:39
  • 2
    unless you can find a tool that is designed for refactoring code, or perl/python/ruby/other? modules that support such activity, you should think about the divide and conquer strategy. Removing all newline chars and then adding back after } and }; sounds like a big enough challenge. If you don't understand how to apply the links you've included, get the most basic step to work. Can you reliably list all of the files in your project as /path/to/file.c (however deep your dir structure is) AND allow for spaces and odd chars in your filenames. That is your first step. Good luck. – shellter May 10 '12 at 02:53

1 Answers1

1

There's a very useful program called indent, it's used to automagically indent C source code. Download it, read its man page and check what it can do. It may solve your problem...

pzanoni
  • 2,979
  • 2
  • 18
  • 18