Removing a pattern in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing a pattern in a line
# 1  
Old 06-12-2014
Removing a pattern in a line

Dear team,

I have a file curve.csv which is generated from oracle and each line has a comment associated with it, I want to get rid of this comment, can you please suggest me a command as how to do it
Eg,
Code:
cat curve.csv
/*data for today curve*/
/*data for text1*/ this is the header
/*data for text2*/ this is the body

the output that I want it
Code:
cat curve.csv
this is the header
this is the body

there is no requirement for comment, can you please suggest?
Thanks
# 2  
Old 06-12-2014
Code:
$ awk 'gsub(/\/\*.*\*\//,x) + 1' curve.csv

This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 06-12-2014
Longhand using CygWin default bash terminal:-

(Note I have not bothered to remove the leading newline as that is easy.)
Code:
#!/bin/bash
> /tmp/comment
> /tmp/nocomments
ifs_str="$IFS"
IFS="/"$'\n'
echo '/*data for today curve*/
/*data for text1*/ this is the header
/*data for text2*/ this is the body' >> /tmp/comment
while read line
do
	text=($line)
	echo "${text[2]:1}" >> /tmp/nocomments
done < /tmp/comment
cat < /tmp/nocomments
IFS="$ifs_str"
exit 0

Resuilts:-
Code:
AMIGA:~> cd /tmp
AMIGA:/tmp> chmod 755 comment.sh
AMIGA:/tmp> ./comment.sh

this is the header
this is the body
AMIGA:/tmp> _

This User Gave Thanks to wisecracker For This Post:
# 4  
Old 06-12-2014
Another way,

Code:
while read line
do
 [ "${line##*/}" ] && echo ${line##*/}
done < file

Note, That check is for if theres only comment and no text in the line, don't print it.
# 5  
Old 06-12-2014
The trouble with these C-Style comments is that they can span multiple lines and that if the comment characters are embedded in quotation marks then they should not be regarded as comments.
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 06-12-2014
Problem with this code is, its deleting the line if its finding the comment on right side of the file, I am in need to remove only /*<any text number etc>*/
this is not working if the line is
Code:
this is the first line  /*print first line*/

---------- Post updated at 07:32 PM ---------- Previous update was at 07:31 PM ----------

Hi, i am using Solaris, so this is not working
# 7  
Old 06-12-2014
Then please give us a few lines of genuine text for us to play with.
As Scrutinizer has quoted......
Quote:
The trouble with these C-Style comments is that they can span multiple lines and that if the comment characters are embedded in quotation marks then they should not be regarded as comments.
......then without the full facts we __can__ pre-empt a possible set of events but this will change the structure from simple to complex...

Once again please post a few lines of genuine text with any private stuff removed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

4. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

5. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

6. Shell Programming and Scripting

Removing spaces from line matching a pattern

Hi, I want to remove the spaces from all the lines matching a particular pattern from my file. For instance in file abc.txt I have following data. Header,This is the header 111,this is 1st record 222, this is 2nd record 333, this is 3rd record Footer,3 records found Footer,111222333 ... (5 Replies)
Discussion started by: decci_7
5 Replies

7. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

8. Shell Programming and Scripting

Deleting pattern without removing line

I am trying to delete a pattern without removing line. I searched a lot in this forum and using those I could come up with sed command but it seems that command does not work. Here's how my file looks like: 1 ./63990 7 1171 ./63990 2 2425 ./63990 9 2539 ./63990 1 3125 ./63990 1 10141... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

9. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

10. Shell Programming and Scripting

removing a line containing a pattern in sed

i need to use sed to remove an entire line containing a pattern stored in a variable say $var1 this var1 will be a URL and will therefore contain slashes any help would be greatly appreciated (1 Reply)
Discussion started by: Fire_Storm
1 Replies
Login or Register to Ask a Question