Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to comment a specific line of a file in Solaris 10? Post 303042676 by abhaydas on Friday 3rd of January 2020 07:22:52 AM
Old 01-03-2020
Thanks Ravinder and MadeInGermany , That helped
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a comment line in a text file

Hi I need to add a comment line at the begining of a text file. The scenario is given below. 1. The number of servers that needs to be updated is around 80 2. The location of the text file in all the servers are the same including the file name. 3. The comment has to be added at the very... (2 Replies)
Discussion started by: orakhan
2 Replies

2. UNIX for Dummies Questions & Answers

how to replace a text of line with a comment line

I want to replace this line : "test compare visible] true" and make it "#test compare visible] true". How can I do it ? And it should be checked in many sub folder files also. (6 Replies)
Discussion started by: manoj.b
6 Replies

3. Shell Programming and Scripting

Comment a line with SED

I have around 25 hosts and each hosts has 4 instance of jboss and 4 different ip attached to it . I need to make some changes to the startup scripts. Any tips appreciated. I have total of 100 instances which bind to 100 different ip address based on instance name. For example File1 ... (1 Reply)
Discussion started by: gubbu
1 Replies

4. Shell Programming and Scripting

uncomment or comment one specific line in a config file

Hello. I want comment or uncomment a ligne in a config file. The file name : /etc/samba/smb.conf Normaly the ligne is uncomment :so the line begin with a tab character followed by passdb backend =\tpassdb backend = In that case I should comment this line ... (2 Replies)
Discussion started by: jcdole
2 Replies

5. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

6. Shell Programming and Scripting

comment a line of the patterns is a the beginning of the line

I need to comment the lines starting with pattern "exclude" or "exclude=". If the work exclude comes at any other part, ignore it. Also, ignore, excludes, excluded etc. Ie only comment the line starting with exclude. File contents. exclude exclude= hi I am excluded excludes excludes= ... (9 Replies)
Discussion started by: anil510
9 Replies

7. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

8. Shell Programming and Scripting

How to comment a specific line of a file?

Hi, I need to comment out (insert # in the front of a line) a line that has entry Defaults requiretty using command-line as I need to do this on hundreds of servers. From Defaults requiretty To #Defaults requiretty I tried something like below but no luck: Please advise,... (3 Replies)
Discussion started by: prvnrk
3 Replies

9. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

10. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies
File::FcntlLock(3pm)					User Contributed Perl Documentation				      File::FcntlLock(3pm)

NAME
File::FcntlLock - File locking with fcntl(2) SYNOPSIS
use File::FcntlLock; my $fs = new File::FcntlLock; $fs->l_type( F_RDLCK ); $fs->l_whence( SEEK_CUR ); $fs->l_start( 100 ); $fs->l_len( 123 ); open my $fh, '<', 'file_name' or die "Can't open file: $! "; $fs->lock( $fh, F_SETLK ) or print "Locking failed: " . $fs->error . " "; $fs->l_type( F_UNLCK ); $fs->lock( $fh, F_SETLK ) or print "Unlocking failed: " . $fs->error . " "; DESCRIPTION
File locking in Perl is usually done using the flock() function. Unfortunately, this only allows locks on whole files and is often implemented in terms of flock(2), which has some shortcomings. Using this module file locking via fcntl(2) can be done (obviously, this restricts the use of the module to systems that have a fcntl(2) system call). Before a file (or parts of a file) can be locked, an object simulating a flock structure must be created and its properties set. Afterwards, by calling the "lock()" method a lock can be set or it can be determined if and which process currently holds the lock. To create a new object representing a flock structure call "new()": $fs = new File::FcntlLock; You also can pass the "new()" method a set of key-value pairs to initialize the objects properties, e.g. use $fs = new File::FcntlLock l_type => F_WRLCK, l_whence => SEEK_SET, l_start => 0, l_len => 100; if you plan to obtain a write lock for the first 100 bytes of a file. Once you have created the object simulating the flock structure the following methods allow to query and in most cases also to modify the properties of the object. "l_type()" If called without an argument returns the current setting of the lock type, otherwise the lock type is set to the argument, which must be either "F_RDLCK", "F_WRLCK" or "F_UNLCK" (for read lock, write lock or unlock). "l_whence()" Queries or sets the "l_whence" property of the flock object, determining if the "l_start" value is relative to the start of the file, to the current position in the file or to the end of the file. The corresponding values are "SEEK_SET", "SEEK_CUR" and "SEEK_END". See also the man page for lseek(2). "l_start()" Queries or sets the start position (offset) of the lock in the file according to the mode selected by the "l_whence" member. See also the man page for lseek(2). "l_len()" Queries or sets the length of the region (in bytes) in the file to be locked. A value of 0 is interpreted as to mean a lock (starting at "l_start") up to the very end of the file. According to SUSv3 negative values for "l_start" are allowed (resulting in a lock ranging from "l_start + l_len" to "l_start - 1") Unfortunately, not all systems allow negative arguments and will return an error when you try to obtain the lock, so please read the fcntl(2) man page of your system carefully for details. "l_pid()" This method allows retrieving the PID of a process currently holding the lock after a call of "lock()" with "F_SETLK" indicated that another process is holding the lock. A call to "lock()" with "F_GETLK" will fill in this value so "l_pid()" can be called. When not initialized the flock objects "l_type" property is set to "F_RDLCK" by default, "l_whence" to "SEEK_SET", and both "l_start" and "l_len" to 0, i.e. the settings for a read lock on the whole file. After having set up the object representing a flock structure you can determine the current holder of a lock or try to obtain a lock by invoking the "lock()" method with two arguments, a file handle (or a file descriptor, the module figures out automatically what it got) and a flag indicating the action to be taken, e.g. $fs->lock( $fh, F_SETLK ); There are three values that can be used as the second argument: "F_GETLK" For "F_GETLK" the "lock()" method determines if and who currently is holding the lock. If no other process is holding the lock the "l_type" field is set to "F_UNLCK". Otherwise the flock structure object is set to the values that prevent us from obtaining a lock. There may be multiple such blocking processes, including some that are themselves blocked waiting to obtain a lock. "F_GETLK" will only make details of one of these visible, and one has no control over which process this is. "F_SETLK" For "F_SETLK" the "lock()" method tries to obtain the lock (when "l_type" is set to either "F_WRLCK" or "F_RDLCK") or releases the lock (if "l_type" is set to "F_UNLCK"). If a lock is held by some other process the method call returns "undef" and errno is set to "EACCESS" or "EAGAIN" (please see the the man page for fcntl(2) for the details). "F_SETLKW" is similar to "F_SETLK" but instead of returning an error if the lock can't be obtained immediately it blocks until the lock is obtained. If a signal is received while waiting for the lock the method returns "undef" and errno is set to "EINTR". On success the method returns the string "0 but true". If the method fails (as indicated by an "undef" return value) you can either immediately evaluate the error number (usingf $!, $ERRNO or $OS_ERROR) or check for it at some later time via the methods discussed below. There are three methods for obtaining information about the reason the the last call of "lock()" for the object failed: "lock_errno()" Returns the error number from the latest call of "lock()". If the last call did not result in an error the method returns "undef". "error()" Returns a short description of the error that happened during the latest call of "lock()" with the object. Please take the messages with a grain of salt, they represent what SUSv3 (IEEE 1003.1-2001) and the Linux, TRUE64, OpenBSD3 and Solaris8 man pages tell what the error numbers mean, there could be differences (and additional error numbers) on other systems. If there was no error the method returns "undef". "system_error()" While the previous method, "error()", tries to return a string with some relevance to the locking operation (i.e. "File or segment already locked by other process(es)" instead of "Permission denied") this method returns the "normal" system error message associated with errno. The method returns "undef" if there was no error. EXPORT F_GETLK F_SETLK F_SETLKW F_RDLCK F_WRLCK F_UNLCK SEEK_SET SEEK_CUR SEEK_END CREDITS
Thanks to Mark Jason Dominus (MJD) and Benjamin Goldberg (GOLDBB) for helpful discussions, code examples and encouragement. Glenn Herteg pointed out several problems and also helped improve the documentation. Julian Moreno Patino also helped correcting the documentation and pointed out problems arising on GNU Hurd (which seems to have only very rudimentary support for locking with fcntl()). AUTHOR
Jens Thoms Toerring <jt@toerring.de> SEE ALSO
perl(1), fcntl(2), lseek(2). perl v5.14.2 2011-10-29 File::FcntlLock(3pm)
All times are GMT -4. The time now is 12:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy