If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > removing specific lines in a file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-04, 13:59
alexandra84 alexandra84 is offline
Registered User
 
Join Date: Aug 2004
Posts: 6
removing specific lines in a file

Another stupid question...
I have a file, I need to remove all the lines in the file that start with a specific character (in this case, #). Is there any easy unix command to do this or should I write a mini program to do it for me?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 08-25-04, 14:16
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
The only stupid question is the one not asked [(c) don't remember]

Code:
ex - myFile.txt <<EOF
%s/^#.*/replacedPattern/g
wq!
EOF
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 08-25-04, 14:28
alexandra84 alexandra84 is offline
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks! That definitely helped
Reply With Quote
  #4 (permalink)  
Old 08-26-04, 06:39
SiverSloth SiverSloth is offline
Registered User
 
Join Date: Jun 2004
Posts: 29
try egrep

Another tool you might try is egrep. To remove lines which start with a #
Code:
egrep -v ^# infile > outfile
The ^ symbol anchors the # to the start of the line so you don't remove a line such as

data # more data

The -v flag means lines other than those which match the pattern.

man egrep for more info
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On