Sponsored Content
Top Forums Shell Programming and Scripting Comment lines in FSTAB using perl Post 302671875 by bakunin on Saturday 14th of July 2012 10:53:17 PM
Old 07-14-2012
Are you insisting in PERL? Because in fact this is a simple operation and to use PERL for this is probably overkill of the extreme sort. The following solution is sed and will do the job:

Code:
sed 's/^[<spc><tab>]*zin46fil01:\/vol\/fil01vol09\/soft1\/\_TOOLS_\/dist \/_TOOLS_\/.dist15/# &/' /etc/fstab > /tmp/sed.$$
mv /etc/fstab /etc/fstab.${DATE}
mv /tmp/sed.$$ /etc/fstab

I assumed the variable "$DATE" here, which is part of my environment, because i like to have date-coded backup files if i let something change via a script. If you don't have such a variable either create one before or even dump the command altogether if you don't need a backup copy.

Replace "<spc>" and "<tab>" with literal spaces/tabs. If you have more than one line to comment out just duplicate the line and change the path accordingly. The "&" in the replacement part means "everything matched by the regexp before":

Code:
sed 's/^[<spc><tab>]*\/path\/to\/mount1/# &/
     s/^[<spc><tab>]*\/path\/to\/mount2/# &/' /etc/fstab > /tmp/sed.$$
mv /etc/fstab /etc/fstab.${DATE}
mv /tmp/sed.$$ /etc/fstab

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to comment multiple lines in unix

hi all, please help me how to comment multiple lines in unix script. thanks in advance --bali (3 Replies)
Discussion started by: balireddy_77
3 Replies

2. UNIX for Dummies Questions & Answers

comment lines

Is there a command to put a comment (#) in a whole part of a shell script? (5 Replies)
Discussion started by: vero_81
5 Replies

3. Shell Programming and Scripting

using awk to comment out lines to the end of file

Hello, I have a file as follow a b c c d d e I would like to write a awk command to insert # from the first occurence of "c" to the end of the files. OUTPUT should be like this a b #c (5 Replies)
Discussion started by: phamp008
5 Replies

4. Shell Programming and Scripting

Need perl regular expression to remove the comment

I need a perl substitution to remove only the comment in the line . That line may have '#' with in double quotes .I used the following , s/(^.*\".+?#.+?\".+?)(#.*)/$1/g It works for , print " not a comment # not a comment " . "not a comment # not a comment" ; # It is a comment ... (3 Replies)
Discussion started by: karthigayan
3 Replies

5. UNIX for Dummies Questions & Answers

Trying to show lines in INI files until the comment character (#)

I have a working directory on a server with over 100 INI files. For the most part, they are configured the same way. Each line will contain 1 or none variables listed from the first character in the line such as VariableName=0. Unfortunately there are comments everywhere using the... (4 Replies)
Discussion started by: hindesite
4 Replies

6. Shell Programming and Scripting

How can i comment out a section between two particular lines

I want to find out which files under /etc have the the following section: and then i would like to comment out the above section in all the files. Please help. (3 Replies)
Discussion started by: proactiveaditya
3 Replies

7. UNIX for Dummies Questions & Answers

Comment lines in file without vi editor

Legends, Can you please help me in following. I need to comment lines from “/tmp/a.txt” from the line A to line B through the command prompt only. Please use variables not direct values like 2 or 5 It can be done with VI editor but it's not matches with my requirement (: 2,5 s/^/#/g). ... (1 Reply)
Discussion started by: sdosanjh
1 Replies

8. Shell Programming and Scripting

Comment ( -- ) lines from 10 to 25 for every .sql file

Platform : RHEL 5.4 I have several .sql files in a directory. I want to comment lines 10 to 25 for all .sql files. How can I do this ? The symbol for comment in SQL is -- eg: -- select salary from emp where empname = 'URS' ; (3 Replies)
Discussion started by: omega3
3 Replies

9. Shell Programming and Scripting

Perl one liner to wrap comment lines

Greetings fellow scripters. I find myself editing multiple files, sometimes with the same bits of information. My bash script, a changelog, and a plist file (OS X). Once I realized this, I thought why not script part of this process (and so it begins). In any case, I've solved several of the... (1 Reply)
Discussion started by: reid
1 Replies

10. UNIX for Beginners Questions & Answers

Remove Comment Lines From Script/Input File

Hello, I have a SAS code that predominantly has comments line and the real code like below and i want to remove ONLY THE COMMENTS from the code in the single line or spanned across multiple lines. /******************************************************************** *** This Is a Comment... (4 Replies)
Discussion started by: arooonatr
4 Replies
getfsent(3x)															      getfsent(3x)

Name
       getfsent, getfsspec, getfsfile, getfstype, setfsent, endfsent - get file system descriptor file entry

Syntax
       #include <fstab.h>
       #include /usr/include/sys/fs_types.h

       struct fstab *getfsent()

       struct fstab *getfsspec(spec)
       char *spec;

       struct fstab *getfsfile(file)
       char *file;

       struct fstab *getfstype(type)
       char *type;

       int setfsent()

       int endfsent()

Description
       All  routines  operate  on the file which contains descriptions of the known file systems.  The routine opens this file.  The routine reads
       the next file system description within opening the file if necessary.  The routine closes the file.

       The and routines sequentially scan the file for specific file system descriptions.  The routine searches for a description with a  matching
       special file name field.  The routine searches for a description with a matching file system path prefix field.	The routine searches for a
       description with a matching file system type field.

       The and each return a pointer to a representation of the description they have matched or read.	Representations are in the format  of  the
       following structure:
       #define	 FSTAB_RW  "rw" /* read-write device	  */
       #define	 FSTAB_RO  "ro" /* read-only device	  */
       #define	 FSTAB_RQ  "rq" /* read-write with quotas */
       #define	 FSTAB_SW  "sw" /* swap device		  */
       #define	 FSTAB_XX  "xx" /* ignore totally	  */

       struct fstab {
	    char *fs_spec; /* block special device name    */
	    char *fs_file; /* file system path prefix	   */
	    char *fs_type; /* rw,ro,sw or xx		   */
	    int  fs_freq;  /* dump frequency, in days	   */
	    int  fs_passno;	/* pass number on parallel dump */
	    char *fs_name; /* name of the file system type */
	    char *fs_opts  /* arbitrary options field	   */
       };

Return Values
       A NULL or 0 is returned, but errno is not set on detection of errors.

Restrictions
       All descriptions are contained in static areas, which should be copied.

Files
       /etc/fstab     File system information file.

See Also
       fstab(5)

																      getfsent(3x)
All times are GMT -4. The time now is 04:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy