![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk, ignore first x number of lines. | trey85stang | Shell Programming and Scripting | 8 | 05-21-2008 01:44 AM |
| Ignore some lines with specific words from file comparison | jakSun8 | Shell Programming and Scripting | 2 | 03-12-2008 09:11 PM |
| How can I ignore only the lines which have # at the begining? | csaha | Shell Programming and Scripting | 1 | 01-30-2006 12:35 AM |
| Make sed ignore lines | Scarlos | Shell Programming and Scripting | 2 | 07-21-2005 07:33 AM |
| Removing duplicate lines ignore case | hellsd | UNIX for Dummies Questions & Answers | 17 | 12-02-2004 07:47 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 scripts process and ignore comment lines. Thanks guys. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
If you want to do only a couple things with the output, filter you source file in a pipeline:
Code:
grep -v '^[[:space:]]*#' /path/to/your/file | your_commands Code:
grep -v '^[[:space:]]*#' /path/to/your/file >/tmp/stripped_source Code:
egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' /path/to/file >/tmp/stripped_file Last edited by hadarot; 08-18-2005 at 05:53 PM. |
|
#3
|
||||
|
||||
|
Try...
Code:
$ cat file1 #line1 #line2 line#3 line4 $ sed '/^ *#/d;s/#.*//' file1 line line4 |
|
#4
|
|||
|
|||
|
Quote:
|
|
#5
|
|||
|
|||
|
If you want your script to behave like the ksh itself (ignore the part of a line after a "#" but use the part before it) you could do the following (replace "<spc>" with a literal space, "<tab>" with a tab char):
Code:
script sed 's/#.*$/;s/^[<spc><tab>]*//;s/[<spc><tab>]*$//;/^$/d' file content of file # this is a line with comments # this too, but starting with blanks command 1 # this line contains an inline comment command 2 "#" # this too, but my script would be confused result command 1 command 2 " bakunin |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|