Removing Multiple Line comments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing Multiple Line comments
# 15  
Old 02-18-2011
I mean here.
This User Gave Thanks to Scrutinizer For This Post:
# 16  
Old 02-18-2011
Still the same... Just first line of comment and last slash gets removed....
# 17  
Old 02-18-2011
Code:
 $ ruby -0777 -ne 'puts $_.gsub(/\/\*.[^\\][^\*]*\*\//m,"")' file

Some text
Text1
Text2
Some text
Note this text 
Note here again

This User Gave Thanks to kurumi For This Post:
# 18  
Old 02-18-2011
If this doesn't work for you:
Code:
sed '
:t
s|\(.*\)/\*.*\*/|\1|
tt
/\/\*/!b
N
bt
'

Try http://sed.sourceforge.net/grabbag/s.../remccoms3.sed
# 19  
Old 02-21-2011
Kurumi...
I get an error that says -0777 not found... and if I give $ ruby <.....>, it says ruby not found...

binlib...
Thanks for your help... Can I have that command in a single line...? Am not sure why it should be a line after another... Doesn't work with me...
# 20  
Old 02-21-2011
There is no reason why it should be in one line. But if you insist, you can use multiple "-e"s:
Code:
sed -e:t -e's|\(.*\)/\*.*\*/|\1|;tt;/\/\*/!b;N;bt'

Most of the time, you can just separate the commands with semicolons, but not with labels.
This User Gave Thanks to binlib For This Post:
# 21  
Old 02-21-2011
See if this works for you:
Code:
#!/usr/bin/ksh
typeset -i mCnt
mOpenFlag="N"
while read mLine
do
  if [[ "${mOpenFlag}" = "Y" ]]; then
    mCnt=`echo "${mLine}" | egrep -c '\*/'`
    if [[ ${mCnt} != 0 ]]; then
      mOpenFlag="N"
      mTmpLine=`echo "${mLine}" | sed -e 's#.*\*/##'`
      if [[ "${mTmpLine}" != "" ]]; then
        echo "${mTmpLine}"
      fi
    fi
    continue
  fi
  mTmpLine=`echo "${mLine}" | sed -e 's#/\*.*\*/##'`
  mCnt=`echo "${mTmpLine}" | egrep -c '/\*'`
  if [[ ${mCnt} != 0 ]]; then
    mOpenFlag="Y"
    mTmpLine=`echo "${mTmpLine}" | sed -e 's#/\*.*##'`
  else
    mCnt=`echo "${mTmpLine}" | egrep -c '\*/'`
    if [[ ${mCnt} != 0 ]]; then
      mOpenFlag="N"
      mTmpLine=`echo "${mTmpLine}" | sed -e 's#.*\*/##'`
    fi
  fi
  if [[ "${mTmpLine}" != "" ]]; then
    echo "${mTmpLine}"
  fi
done < input_file

This User Gave Thanks to Shell_Life For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

2. Shell Programming and Scripting

How to ignore comments at the end of the each line?

Hi All, I am reading the host file by ignoring the comments and write it to the other file. I am reading with regular expression for IP address. grep -E '^{1,3}\.{1,3}\.{1,3}\.{1,3}' $inputFile | awk '{for(i=2;i<=NF;i++)print $1,$i}' > $DR_HOME/OS/temp After that am reading each host... (4 Replies)
Discussion started by: sharsour
4 Replies

3. UNIX for Dummies Questions & Answers

Remove multi line and single line comments

Hi, I am trying to remove multi line and single line comments like examples below I have tried this pattern. it works fine for single line comments and multi line comments in a single line only. but this fails when the comments are extended in multiple lines as shown in the comment 2 of... (3 Replies)
Discussion started by: ahmedwaseem2000
3 Replies

4. Shell Programming and Scripting

Removing SAS multi line comments in UNIX

i have to remove the commented (/* . . . .*/) part which starts in one line and ends in other.help me with generic code because i have 1000 to 10k lines code which i have to remove. data one; set work.temp; input name age; infile filename; /* dfsdf dsfs sdfdf dsdd sdfsf sdfsf sfs... (4 Replies)
Discussion started by: saaisiva
4 Replies

5. Shell Programming and Scripting

Removing carriage return/line feeds on multiple lines

I would like to remove carriage returns/line feeds in a text file, but in a specific cadence: Read first line (Header Line 1), remove cr/lf at the end (replace it with a space ideally); Read the next line (Line of Text 2), leave the cr/lf intact; Read the next line, remove the cr/lf; Read... (14 Replies)
Discussion started by: tomr2012
14 Replies

6. Shell Programming and Scripting

How to filter only comments while reading a file including line break characters.

How do I filter only comments and still keep Line breaks at the end of the line!? This is one of the common tasks we all do,, How can we do this in a right way..!? I try to ignore empty lines and commented lines using following approach. test.sh # \040 --> SPACE character octal... (17 Replies)
Discussion started by: kchinnam
17 Replies

7. Shell Programming and Scripting

Sed script, changing all C-comments to C++-comments

I must write a script to change all C++ like comments: // this is a comment to this one /* this is a comment */ How to do it by sed? With file: #include <cstdio> using namespace std; //one // two int main() { printf("Example"); // three }//four the result should be: (2 Replies)
Discussion started by: black_hawk
2 Replies

8. Shell Programming and Scripting

Removing end of line to merge multiple lines

I'm sure this will be an easy question for you experts out there, but I have been searching the forum and working on this for a couple hours now and can't get it right. I have a very messy data file that I am trying to tidy up - one of the issues is some records are split into multiple lines: ... (4 Replies)
Discussion started by: tink
4 Replies

9. Shell Programming and Scripting

removing comments from file

I'm doing manual way to add and remove "#" on etc/services. Is there anyway I can modify the file using awk or sed or any other program. I use vi to modify /etc/services for enabling telnet , the problem is I don't know how to do it automatically in script. production state: #telnet ... (9 Replies)
Discussion started by: skully
9 Replies

10. Solaris

Removing user from multiple groups via command line

Want to know if any, a command line parameter(s) of removing a user from multiple groups without using any ineractive application? (1 Reply)
Discussion started by: jquizon62
1 Replies
Login or Register to Ask a Question