The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pattern matching problem namishtiwari Shell Programming and Scripting 2 05-23-2008 07:33 AM
Pattern Matching in UNIX maxmave Shell Programming and Scripting 2 05-14-2008 03:21 PM
problem with CASE pattern matching gummysweets Shell Programming and Scripting 2 03-18-2008 11:30 AM
ksh pattern matching ripat Shell Programming and Scripting 5 02-10-2008 04:44 PM
pattern matching problem rein Shell Programming and Scripting 8 10-26-2007 11:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-02-2008
maxmave maxmave is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 21
Pattern Matching problem in UNIX

Hello All,

I need help I have a problem in searching the pattern in a file

let us say the file contains the below lines

line 1 USING *'/FILE/FOLDER/RETURN')
.................
.................
line 4 USING *'/FILE/FOLDER/6kdat1')
line 5 USING *'/FILE/FOLDER/4kdat1')
.................
.................
line 8 USING *'/FILE/FOLDER/TMPSPACE')
.................
line 9 USING *FILE '/FILE/FOLDER/TEST'100004)
.................
line 11 USING *FILE '/FILE/FOLDER/TEST'2000)
.................
.................
line 14 USING *FILE '/FILE/FOLDER/TEST'2000)
.................
line 16 USING *FILE '/FILE/FOLDER/TEST'3000)

Actually i want to search a pattern in the file, lets say USING *, if the pattern is found then get each line

for example the pattern is found in the following lines line 1,4,5,8,9,11,14,16

Then get each line and go to the end of the line and

check whether the line ends with a number say here in line 9,11,14,16 it ends with a number but with ) as the last character.

and replace the number with another input string.

Actually i tried lot of options in PERL but could not get a proper solution for this.

Can anyone please help in this regard.

Thanks

Rahul
  #2 (permalink)  
Old 06-02-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Code:
awk -F"[')]"  '/USING \*/ && $3!~/[0-9].*/ ; /USING \*/ && $3~/[0-9].*/{sub($3,"Word"); print }'  filename
  #3 (permalink)  
Old 06-03-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
perl -pe 's/(.* USING .*\D)\d+\)/$1 something)/' file
The regular expression looks for anything (.*) followed by "USING" with spaces on both sides, followed by anything, followed by a non-number (\D). The parentheses capture this match into $1. Then outside the parentheses we look for a number with one or more digits (\d+) followed by a closing parenthesis (with a backslash, to match it literally). This is replaced with $1 followed by "something" (you didn't say what exactly) followed by a closing parenthesis.

It's not so much a Perl question as a regex question, really.
Closed Thread

Bookmarks

Tags
perl, perl regex, regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0