Sponsored Content
Top Forums Shell Programming and Scripting regex matches from lines in file Post 302601674 by pjlotiya on Friday 24th of February 2012 06:43:07 AM
Old 02-24-2012
thx..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace if regex on specific column matches expression?

I am attempting to convert rewrite rules to Nginx, and since due to the mass amount of rewrites we must convert, I've been trying to write a script to help me on a specific part, easily. So far I have this: rewrite ^action/static/(+)/$ staticPage.php?pg=$1&%$query_string; What I want done... (5 Replies)
Discussion started by: EXT3FSCK
5 Replies

2. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

3. Shell Programming and Scripting

Grep regex matches, groups

Hello, I am searching all over the place for this, just not finding anything solid :( I want to do be able to access the groups that are matched with grep (either with extended regex, or perl compatible regex). For instance: echo "abcd" | egrep "a(b(c(d)))" Of course this returns... (1 Reply)
Discussion started by: Rhije
1 Replies

4. Shell Programming and Scripting

Merge lines from one file if pattern matches

I have one comma separated file (a.txt) with two or more records all matching except for the last column. I would like to merge all matching lines into one and consolidate the last column, separated by ":". Does anyone know of a way to do this easily? I've searched the forum but most talked... (6 Replies)
Discussion started by: giannicello
6 Replies

5. Shell Programming and Scripting

script to delete lines from a txt file if pattern matches

File 6 dbnawldb010-b office Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/09/11 03:24:04 42 luigi-b IPNRemitDB Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/10/11 00:41:36 6 ebs-sqldev1-b IPNTracking Memphis_Corp_SQL_Diff... (4 Replies)
Discussion started by: ajiwww
4 Replies

6. Shell Programming and Scripting

SED Replacing all but one regex match on a line or specific matches

Hi, I'm attempting to rename some files that have spaces in them. Without linking sed commands together is it possible to replace the first three "." to " ". File.name.is.long.ext -> File name is long.ext I can get the desired effect with echo "File.name.is.long.ext" | sed 's/\./ /g;s/... (5 Replies)
Discussion started by: vectox
5 Replies

7. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

8. Shell Programming and Scripting

Required 3 lines above the file and below file when string matches

i had requirement like i need to get "error" line of above 3 and below 3 from a file .I tried with the below script.But it's not working. y='grep -n -i error /home/file.txt|cut -c1' echo $y head -$y /home/file.txt| tail -3 >tmp.txt tail -$y /home/file.txt head -3 >>tmp.txt (4 Replies)
Discussion started by: bhas85
4 Replies

9. Shell Programming and Scripting

Exclude lines in a file with matches with multiple Strings using egrep

Hi I have a txt file and I would like to use egrep without using -v option to exclude the lines which matches with multiple Strings. Let's say I have some text in the txt file. The command should not fetch lines if they have strings something like CAT MAT DAT The command should fetch me... (4 Replies)
Discussion started by: Sathwik
4 Replies

10. Shell Programming and Scripting

awk to remove lines in file if specific field matches

I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :). grep grep -v -F -f targets.bed sort_list grep -vFf sort_list targets awk awk -F, ' > FILENAME == ARGV {to_remove=1; next} > ! ($5 in... (2 Replies)
Discussion started by: cmccabe
2 Replies
File(3pm)						User Contributed Perl Documentation						 File(3pm)

NAME
Proc::PID::File - a module to manage process id files SYNOPSIS
use Proc::PID::File; die "Already running!" if Proc::PID::File->running(); Process that spawn child processes may want to protect each separately by using multiple pidfiles. my $child1 = Proc::PID::File->new(name => "lock.1"); my $child2 = Proc::PID::File->new(name => "lock.2"); which may be checked like this: <do-something> if $child1->alive(); and should be released manually: $child1->release(); DESCRIPTION
This Perl module is useful for writers of daemons and other processes that need to tell whether they are already running, in order to prevent multiple process instances. The module accomplishes this via *nix-style pidfiles, which are files that store a process identifier. The module provides two interfaces: 1) a simple call, and 2) an object-oriented interface Simple Interface The simple interface consists of a call as indicated in the first example of the Synopsis section above. This approach avoids causing race conditions whereby one instance of a daemon could read the pidfile after a previous instance has read it but before it has had a chance to write to it. running [hash[-ref]] The parameter signature for this function is identical to that of the ->new() method described below in the OO Interface section of this document. The method's return value is the same as that of ->alive(). OO Interface The following methods are provided: new [hash[-ref]] This method is used to create an instance object. It automatically calls the ->file() method described below and receives the same paramters. For a listing of valid keys in this hash please refer to the aforementioned method documentation below. In addition to the above, the following constitute valid keys: verify = 1 | string This parameter implements the second solution outlined in the WARNING section of this document and is used to verify that an existing pidfile correctly represents a live process other than the current. If set to a string, it will be interpreted as a regular expression and used to search within the name of the running process. Alternatively, a 1 may be passed: For Linux/FreeBSD, this indicates that the value of $0 will be used (stripped of its full path); for Cygwin, $^X (stripped of path and extension) will be used. If the parameter is not passed, no verification will take place. Please note that verification will only work for the operating systems listed below and that the OS will be auto-sensed. See also DEPENDENCIES section below. Supported platforms: Linux, FreeBSD, Cygwin debug Any non-zero value turns debugging output on. Additionally, if a string is passed containing the character M, the module name will be prefixed to the debugging output. file [hash[-ref]] Use this method to set the path of the pidfile. The method receives an optional hash (or hash reference) with the keys listed below, from which it makes a path of the format: $dir/$name.pid. dir Specifies the directory to place the pid file. If left unspecified, defaults to /var/run. name Indicates the name of the current process. When not specified, defaults to basename($0). alive Returns true when the process is already running. Please note that this call must be made *after* daemonisation i.e. subsequent to the call to fork(). If the verify flag was set during the instance creation, the process id is verified, alternatively the flag may be passed directly to this method. touch Causes for the current process id to be written to the pidfile. release This method is used to delete the pidfile and is automatically called by DESTROY method. It should thus be unnecessary to call it directly. locktime [hash[-ref]] This method returns the mtime of the pidfile. AUTHOR
Erick Calder <ecalder@cpan.org> ACKNOWLEDGEMENTS
1k thx to Steven Haryanto <steven@haryan.to> whose package (Proc::RID_File) inspired this implementation. Our gratitude also to Alan Ferrency <alan@pair.com> for fingering the boot-up problem and suggesting possible solutions. DEPENDENCIES
For Linux, FreeBSD and Cygwin, support of the verify option requires availability of the ps utility. For Linux/FreeBSD This is typically found in the procps package. Cygwin users need to run version 1.5.20 or later for this to work. WARNING
This module may prevent daemons from starting at system boot time. The problem occurs because the process id written to the pidfile by an instance of the daemon may coincidentally be reused by another process after a system restart, thus making the daemon think it's already running. Some ideas on how to fix this problem are catalogued below, but unfortunately, no platform-independent solutions have yet been gleaned. - leaving the pidfile open for the duration of the daemon's life - checking a "ps" to make sure the pid is what one expects (current implementation) - looking at /proc/$PID/stat for a process name - check mtime of the pidfile versus uptime; don't trust old pidfiles - try to get the script to nuke its pidfile when it exits (this is vulnerable to hardware resets and hard reboots) - try to nuke the pidfile at boot time before the script runs; this solution suffers from a race condition wherein two instances read the pidfile before one manages to lock it, thus allowing two instances to run simultaneously. SUPPORT
For help and thank you notes, e-mail the author directly. To report a bug, submit a patch or add to our wishlist please visit the CPAN bug manager at: http://rt.cpan.org AVAILABILITY
The latest version of the tarball, RPM and SRPM may always be found at: http://perl.arix.com/ Additionally the module is available from CPAN. LICENCE
This utility is free and distributed under GPL, the Gnu Public License. A copy of this license was included in a file called LICENSE. If for some reason, this file was not included, please see http://www.gnu.org/licenses/ to obtain a copy of this license. $Id: File.pm,v 1.16 2004-04-08 02:27:25 ekkis Exp $ perl v5.10.0 2010-04-25 File(3pm)
All times are GMT -4. The time now is 01:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy