Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignoring the hash symbol 1

Status
Not open for further replies.

blx

MIS
Oct 9, 2002
23
GB
Hi All,
I wonder if someone can help. I've created a script that takes its input from a separate file. The contents of the file are read line-by-line, and each line must be exactly as it appears.
I would like to add some comments to this file but want the script to ignore anything with a # symbol.
Grateful if anyone could tell me how the calling script can ignore the # (hash) symbol.

Thanks
Blx
 
post a portion of the script that 'reads/parses' the data file. The solution may depend on your original script. vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I agree with vgersh, and think that an awk solution is probably the best for this.

Hypothetically, say my file looks like:

a=12
b=15
#these two variables above will be eval'ed
c=13
d=14 #this comment could cause trouble
#this one won't
e=34
##stuff
##more stuff

A script like this(with the generous debugging
commented out)
Code:
BEGIN {a=1} 
{
        if ($0 ~ /^#/) {
            printf &quot;Found match at line %d\n&quot;, NR
            next
         }
         
        if (match($0,/#.*/) > 0) {
             line = substr($0,RSTART,RLENGTH)
             printf &quot;Found match data: %s and line no %d\n&quot;, line, NR
             sub(line,&quot;&quot;,$0)
             arra[a] = $0
             a++
             next
         }
         printf &quot;At element: %d\n&quot;, a
         arra[a] = $0
         a++
  }
   END {
        for (i=1 ; i <= a ; i++) {
             print arra[i]
        }
   }
Produces:
a=12
b=15
c=13
d=14
e=34

Which may be what you want.

 
sorry, here's a portion:

for resources in `cat $list_dir/$Administrator`
do
wln $resources /Administrators/$Administrator
done


The script calls this file:


@RemoteControl:RC.ADMINS.DESKTOPS
# List the collections here
/Library/imp_TMF_TGC::CollectionGUI helpdesk_tasks

The line in Green is the line I want to use as a comment. Everything else in the file is parsed as I would expect and has been tested.

Thanks
Blx
 
grep -v &quot;#&quot; yourfile
will eliminate all lines with &quot;#&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top