Removing lines having #


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing lines having #
# 1  
Old 04-28-2009
Question Removing lines having #

I have a script which goes to different directories and gives the values of all the input parameters, Something as follows

HTML Code:
  cd /opt
grep script-filter = yes *.conf
grep user-and-group-in-same-suffix = yes *.conf
grep worker-threads = 300 *.conf
grep failover-auth = *.conf
grep failover-password = *.conf
netstat -rn
cd /opt/Pddirector/etc
grep sync = *.conf
The result is a output which is as follows
Code:
[JB007@mac901 ~]$ ./VerifyConf.sh 
grep: =: No such file or directory
grep: yes: No such file or directory
# are added to this list then the option [script-filtering]script-filter
[script-filtering]
script-filter = yes
# When script-filter is set to yes, enabling this flag will rewrite
# are added to this list then the option [script-filtering]script-filter
[script-filtering]
script-filter = yes
# When script-filter is set to yes, enabling this flag will rewrite
grep: =: No such file or directory
grep: yes: No such file or directory
# user-and-group-in-same-suffix
user-and-group-in-same-suffix = yes
# user-and-group-in-same-suffix
user-and-group-in-same-suffix = yes
grep: =: No such file or directory

Im trying to just get the output without the lines having the "#"

Please help,

Thanks in advance.
JBSmilie
# 2  
Old 04-28-2009
You could try adding another grep to filter out the lines beginning with '#':

grep script-filter = yes *.conf | grep -v '#'

Hope this helps.
# 3  
Old 04-28-2009
To remove comment lines starting with a hash character:

Code:
cat filename | sed -e "/^#/d"

# 4  
Old 04-28-2009
Quote:
Originally Posted by methyl
To remove comment lines starting with a hash character:

Code:
cat filename | sed -e "/^#/d"

kinda UUOC-ish
# 5  
Old 04-28-2009
Please post cat-less version.
# 6  
Old 04-28-2009
put filename at the end of the sed command
# 7  
Old 04-28-2009
Thx. Prefer left-to-right top-to-bottom in scripts.
Your method is faster in script execution but slower for students to follow.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

3. 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

4. Shell Programming and Scripting

Removing lines from a file

Hi, I have a linux server that was hacked and I have a bunch of files that sporadically contain the following lines through out the file: <?php eval(base64_decode("Xxxxxxxxxxxxxx/xxxxxxxx")); I did't put the exact lines of the file in this post. The "Xxxx" are random letters/numbers.... (8 Replies)
Discussion started by: nck
8 Replies

5. Shell Programming and Scripting

Removing lines with condition

Hello guys, I need help with a script for removing lines that does not satisfy a condition. For example if a file has these lines: aaaa bbbb cccc aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll aaaa bbbb cccc jjjj kkkk lllll dddd eeee ffff dddd eeee ffff Then I want... (4 Replies)
Discussion started by: jaysean
4 Replies

6. Shell Programming and Scripting

Removing last two lines

I have an awk script that replaces ">" with % %> %< SOURCE", ++i %( PHASE 1", i I use the following script />/ { if ( FNR > 1 ) { print "%)" print "%>" } print "" print "%< SOURCE", ++i (11 Replies)
Discussion started by: kristinu
11 Replies

7. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

8. Shell Programming and Scripting

Removing lines with sed

Here is some code output that I have: architecture ppc cputype CPU_TYPE_POWERPC cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 4096 size 184464 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 192512 ... (5 Replies)
Discussion started by: pcwiz
5 Replies

9. Shell Programming and Scripting

Removing Blank Lines

Hi i have the below lines from a file 7538 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

10. Shell Programming and Scripting

Removing lines within a file

Hi There, I've written a script that processes a data file on our system. Basically the script reads a post code from a list file, looks in the data file for the first occurrence (using grep) and reads the line number. It then tails the data file, with the line number just read, and outputs to a... (3 Replies)
Discussion started by: tookers
3 Replies
Login or Register to Ask a Question