Sponsored Content
Top Forums Shell Programming and Scripting need help guys for Regular expression in awk Post 302135986 by user_prady on Friday 14th of September 2007 12:49:28 AM
Old 09-14-2007
need help guys for Regular expression in awk

Hello Experts,

Please help me to cope with the following problem

I ve patterens like

Input
Noptx(5) // remain the same
-*Nop(3);
Nop(9);
--Nop(8); // remain the same d3
**---Nop(7); //remain the same d3
**---Nop(7);
*--Nop(6);
--**Nop(5);
-Nop(4);
Nop(3);

- represents a space
* represents a tab space
Desired OUPUT

Noptx(5) // remain the same
-*Nop(6);
Nop(18);
--Nop(8); // remain the same d3
**---Nop(7); //remain the same d3
**---Nop(14);
*--Nop(12);
--**Nop(10);
-Nop(8);
Nop(6);


I want to change the no to two times but which matches the below patteren

CASE-1: Zero or more spaces/tabs then Nop AND
CASE-2: The line should not end with d3 .

Basically if both patteren matches then double the no inbetween ()
Previously I ve a suggestion but that wont work for the first statement in my input file

awk -F '\\([@- ]*|\\)' 'NF==3{sub($2,$2*5)};1' file1

Now my code only does the CASE-1 but how to overcome both I ve no idea .

gawk '
/^[ \t]*Nop\(/{
split($0, a, /\(|\)/);
print a[1] "(" a[2]*2 ")" a[3] "// d3" >> "/tmp/my_tmp";
next
}
{ print $0 > "/tmp/my_tmp" } ' file



pls help.......
Regards
User_Prady

Last edited by user_prady; 09-14-2007 at 03:18 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expression query in AWK

I have a varable(var1) in a AWK script that contain data in the following format - I need to extract timestamp,priority and log message.I can extract these by using split function but i don't want to use it, since i want to extract it in one go. I have some difficulties in doing it using... (3 Replies)
Discussion started by: omprasad
3 Replies

2. Shell Programming and Scripting

awk and regular expression

Ive got a file with words and also numbers. Bla BLA 10 10 11 29 12 89 13 35 And i need to change "10,29,89,25" and also remove anything that contains actually words... (4 Replies)
Discussion started by: maskot
4 Replies

3. UNIX for Dummies Questions & Answers

regular expression and awk

I can print a line with an expression using this: awk '/regex/' I can print the line immediately before an expression using this: awk '/regex/{print x};{x=$0}' How do I print the line immediately before and then the line with the expression? (2 Replies)
Discussion started by: nickg
2 Replies

4. Shell Programming and Scripting

Regular expression query in AWK

Hi, I have a string like this-->"After Executing service For 10 Request" in this string i need to extract "10". the contents of the string is variable and "10" appears before "For" and after "Request" i.e, in this format "For x Request" I need to extract the value of x. How to do this in AWK?... (10 Replies)
Discussion started by: omprasad
10 Replies

5. Shell Programming and Scripting

Awk regular expression - I need exactly 1 occurrence of it

Hi all, I am processing a file with awk that looks like this: " 0.0021 etc 0.0123 etc 0.1234 etc ... 0.5324 etc 0.5434 etc 0.6543 etc ... 1.0344 etc 1.1344 etc ... 1.5345 etc 1.5632 etc " I need to print out only the lines that have '0' or '5' after the comma, plus I need only... (11 Replies)
Discussion started by: ioannisp
11 Replies

6. Shell Programming and Scripting

Regular expression in AWK

Hello world, I was wondering if there is a nicer way to write the following code (in AWK): awk ' FNR==NR&&$1~/^m$/{tok1=1} FNR==NR&&$1~/^m10$/{tok1=1} ' my_file In fact, it looks for m2, m4, m6, m8 and m10 and then return a positive flag. The problem is how to define 10 thanks... (3 Replies)
Discussion started by: jolecanard
3 Replies

7. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

8. Shell Programming and Scripting

awk regular expression

Hello, I have big files which I wanna filter them based on first column. first column should be one of these strings: chr2L || chr2R || chr3L || chr3R || chr4 || chrX and something like chr2Lh or chrY or chrM3L is not accepted. I used the following command: awk '{ if ($1=="chr2L" ||... (5 Replies)
Discussion started by: @man
5 Replies

9. Shell Programming and Scripting

Problem with Regular expression in awk

Hi, I have a file with two fields in it as shown below 14,30 28,30 16,30 22,30 21,30 3,30 Fields are separated by comma ",". I've been trying to validate the file based on the condition "each field must be a numeric value" I am using HP-UX OS. I have tried the following awk... (4 Replies)
Discussion started by: meetsriharsha
4 Replies

10. Shell Programming and Scripting

awk regular expression search

Hi All, I would like to search a regular expression by passing as an i/p variableto AWK. For Example :: 162.111.101.209.9516 162.111.101.209.41891 162.111.101.209.9516 162.111.101.209.9517 162.111.101.209.41918 162.111.101.209.9517 162.111.101.209.41937 162.111.101.209.41951... (7 Replies)
Discussion started by: Girish19
7 Replies
FvwmAuto(1)							   Fvwm Modules 						       FvwmAuto(1)

NAME
FvwmAuto - the fvwm auto-raise module SYNOPSIS
Module FvwmAuto Timeout [-passid] [-menter|-menterleave|-mfocus] [EnterCommand [LeaveCommand]] FvwmAuto can only be invoked by fvwm. Command line invocation of the FvwmAuto will not work. DESCRIPTION
The FvwmAuto module is most often used to automatically raise focused windows. INVOCATION
The correct syntax is: Module FvwmAuto Timeout [-passid] [-menter|-menterleave|-mfocus] [EnterCommand [LeaveCommand]] AddToMenu Modules + "Auto Raise (300 ms)" Module FvwmAuto 300 + "Auto Raise/Lower" Module FvwmAuto 300 "Silent Raise" "Silent Lower" The Timeout argument is required. It specifies how long a window must retain the keyboard input focus before the command is executed. The delay is measured in milliseconds, and any integer greater than zero is valid. If the literal option -passid is given, the window id of the window just entered or left is appended to the command that is sent to fvwm. This can be used with the WindowId command of fvwm. The options -menter, -menterleave and -mfocus influence the actions FvwmAuto reacts to. No more than one of the options can be chosen. In -mfocus mode, FvwmAuto raises the window that has the focus. In -menter mode, FvwmAuto raises the window under the pointer when the pointer enters a window. The LeaveCommand is executed on the window that was below the pointer before it entered the new window. When the pointer leaves a window and enters the root window, the EnterCommand is executed too, but without a window to operate on. In -menterleave mode, FvwmAuto works just like in -menter mode, but the LeaveCommand is also executed if the pointer moves out of a window but does not enter a new window. The latter two modes of operation are useful with windows that do not accept the focus. Note: -menterleave mode can interfere with popup windows of some applications. One example is the zoom menu of Ghostview. Please do not complain about this to us - it is a bug in Ghostview. EnterCommand and LeaveCommand are optional. EnterCommand is executed Timeout milliseconds after a window gets the input focus, LeaveCom- mand is executed Timeout milliseconds after the window has lost focus. Note that you always should use the 'Silent' keyword before the command itself. FvwmAuto prepends "Silent " to the command string on its own if yor forget this. Without this prefix fvwm would ask you for a window to act on if the window has died before the command sent by FvwmAuto has been processed by fvwm. This can for example happen with popup menus. "Silent Raise" is the default for EnterCommand, but any fvwm function is allowed. I would not use "Close" or "Destroy" with a low timeout, though. The LeaveCommand can be handy for a tidy desktop. Experiment with: Module FvwmAuto 0 Nop "Silent Lower" Module FvwmAuto 0 Nop "Silent Iconify" An example for auto raising windows with ClickToFocus: Style * ClickToFocus FvwmAuto 0 -menter "Silent Raise" An example for auto raising and lowering only some windows: To start FvwmAuto: FvwmAuto 0 -passid -menter "Silent selective_raiselower raise" "Silent selective_raiselower lower" And put this in your .fvwm2rc: AddToFunc selective_raiselower + I WindowId $1 (FvwmIconMan) $0 + I WindowId $1 (FvwmButtons) $0 + I WindowId $1 (xclock) $0 More complex example (three FvwmAuto's are running): DestroyFunc RestoreIconified AddToFunc RestoreIconified + I Current (Iconic) Iconify false DestroyFunc RegisterFocus AddToFunc RegisterFocus + I Exec date +"%T $n focused" >>/tmp/focus-stats.txt DestroyFunc RegisterUnfocus AddToFunc RegisterUnfocus + I Exec date +"%T $n unfocused" >>/tmp/focus-stats.txt KillModule FvwmAuto Module FvwmAuto 250 Raise Nop Module FvwmAuto 800 RestoreIconified Nop Module FvwmAuto 0 RegisterFocus RegisterUnfocus NOTES
There is a special Raise/Lower support in FvwmAuto. It was added to improve Raise/Lower callbacks, since most of FvwmAuto usages is auto- raising or auto-lowering. This improvement includes locking on M_RAISE_WINDOW and M_LOWER_WINDOW packets and not raising/lowering explic- itly raised windows. The special Raise/Lower support is enabled only when either EnterCommand or LeaveCommand contain substring "Raise" or "Lower". You can use this fact to enable/disable any special support by renaming these commands, if FvwmAuto does not automatically do want you expect it to do. Using FvwmAuto in conjunction with EdgeCommand can be even more powerful. There is a short example in the fvwm man page. AUTHOR
FvwmAuto just appeared one day, nobody knows how. FvwmAuto was simply rewritten 09/96, nobody knows by whom. 3rd Berkeley Distribution 09 May 2010 (2.5.30) FvwmAuto(1)
All times are GMT -4. The time now is 03:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy