sed command : print lines having no # at the begining


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command : print lines having no # at the begining
# 1  
Old 02-28-2011
sed command : print lines having no # at the begining

I am trying to print those line which has no # in the begining of the line.
The sed I used for this purpose as shown below is not giving the required output.

Code:
echo 'PDE 5600' | sed -n 's/^\!#/&/p'

Where lies the problemSmilie

Last edited by hiten.r.chauhan; 02-28-2011 at 04:02 AM.. Reason: error in typing
# 2  
Old 02-28-2011
Code:
sed -n '/^[^#]/p'

# 3  
Old 02-28-2011
Code:
$ echo 'PDE 5600' | ruby -e 'print  if !gets[/^\s+#/] '
PDE 5600
$ echo '   #PDE 5600' | ruby -e 'print  if !gets[/^\s+#/] '
$ echo '   #PDE 5600' | ruby -e 'print  if !gets[/^\s+#/] '
$

# 4  
Old 02-28-2011
BY GREP
Code:
grep -v ^#

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sed to print first n lines and last n lines of an output.

Use sed to print first n lines and last n lines of an output. For example: n=10 Can it be done? Thanks. (7 Replies)
Discussion started by: carloszhang
7 Replies

2. UNIX for Dummies Questions & Answers

Adding variable value in the begining of all lines present in a file.

I am getting the varible value from a grep command as: var=$(grep "Group" File1.txt | sed 's/Group Name*//g;s/,//g;s/://g;s/-//g') which leaves me the value of $var=xyz. now i want to append $var value in the begining of all the lines present in the file. Can u please suggest? Input file: 1... (10 Replies)
Discussion started by: rade777
10 Replies

3. Shell Programming and Scripting

sed print first line before regexp and all lines after

Hi All I'm trying to extract the line just above a regexp and all lines after this. I'm currently doing this in two steps sed -n -e "/^+---/{g;p;}" -e h oldfile.txt > modified.txt sed -e "1,/^+---/d" -e "/^$/d" oldfile.txt >>modified.txt Sample sometext will be here sometext will be... (3 Replies)
Discussion started by: Celvin VK
3 Replies

4. Shell Programming and Scripting

sed print all lines between second and third identical lines

I am trying to extract a table of data (mysql query output) from a log file. I need to print everything below the header and not past the end of the table. I have spent many hours searching with little progress. I am matching the regexp +-\{99\} with no problem. I just can't figure out how to print... (5 Replies)
Discussion started by: godfreydanials
5 Replies

5. Solaris

sed command to print lines after expression

Hi guys. I need a sed command to print like 10 lines after a regular expression is found in the log. Can anyone help me out. Thanks ---------- Post updated at 10:52 AM ---------- Previous update was at 10:34 AM ---------- never mind. I just did the search bewteen two expressions. (1 Reply)
Discussion started by: jamie_collins
1 Replies

6. Shell Programming and Scripting

read file-print lines in sed

Hello! Im trying to read file contents. Then, print out every line that has "/bens/here" in the file that was read. cat /my/file.now | sed '/bens/here/p' I keep getting the error asking if I need to predeclare sed? What does predeclaring sed mean? Thanks! Ben (2 Replies)
Discussion started by: bigben1220
2 Replies

7. Shell Programming and Scripting

sed print all lines after pattern match

HiCan someone show me how to print all lines from a file after a line matching a pattern using sed?Thanks (13 Replies)
Discussion started by: steadyonabix
13 Replies

8. Shell Programming and Scripting

move the last word to begining of next line - SED

Hello, I'm trying to move the last word of matching pattern to the begining of next line. Appreciate if anyone post the script. From the below line I'm getting the last word, Note: this word also appears in many places in my file #return the last word of line that contains ListenPort sed... (4 Replies)
Discussion started by: baskar
4 Replies

9. Shell Programming and Scripting

How can I ignore only the lines which have # at the begining?

From the below file I want to grep only the lines except the comment sections. But grep -v "#" is eliminating the last line because it has one # in between. Any idea how can I ignore only the lines which have # at the begining (I mean comment lines) ? Thanks a lot to all in advance C Saha (1 Reply)
Discussion started by: csaha
1 Replies

10. Shell Programming and Scripting

Ignore Lines Begining With #

Is there a standard way to make a shell script read a file, or list, and skip each line that contains # at the begining, or ignores the content starting after a # in line? I'm looking to mimic the way commenting in a shell script normally works. This way I can comment my text files and lists my... (4 Replies)
Discussion started by: sysera
4 Replies
Login or Register to Ask a Question