Sponsored Content
Full Discussion: simple awk problem
Top Forums Shell Programming and Scripting simple awk problem Post 302563575 by delphys on Tuesday 11th of October 2011 03:06:33 PM
Old 10-11-2011
simple awk problem

Hello;

I have the following log file:

Code:
10/11/11  10:42:02  LOCK Q Userid:284 Username=root UserPID:23158 Device:marlin batch
10/11/11  10:42:02         TableNr:226 TableName:iatkn RecId:116290398 Flags:X    Q H
10/11/11  10:42:02     LOCK CONTENTION X
10/11/11  10:42:02                  Userid:320 Username:root UserPID:19808 Device:marlin batch
10/11/11  10:42:03                  Table:iatkn RecId:116290398 Flags:X
10/11/11  10:42:03  /uscripts/dsl/com/snmpalert.sh "MESSAGE:1040" "deva Q_LOCK: Userid:284 Username:root UserPID:23158 Device:marlin batch TableNr:226 TableName:iatkn RecId:116290398 Flags:X    Q H WAITING FOR X_LOCK: Userid:320 Username:root UserPID:19808 Device:marlin batch Flags:X       "


I want to select the lines so that I get the following output:

Code:
10/11/11  10:42:02  LOCK Q Userid:284 Username=root UserPID:23158 Device:marlin batch
10/11/11  10:42:02     LOCK CONTENTION X
10/11/11  10:42:02                  Userid:320 Username:root UserPID:19808 Device:marlin batch


I tried the following but obviously it is not working.

Code:
awk '/LOCK Q/ || /LOCK CONTENTION X/ {getline;print}' deva.db_locks_exc2.status
10/11/11  10:42:02         TableNr:226 TableName:iatkn RecId:116290398 Flags:X    Q H
10/11/11  10:42:02                  Userid:320 Username:root UserPID:19808 Device:marlin batch

Thank you for any help

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 10-11-2011 at 06:21 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple Scripting Problem

Hi there, I was trying to add a line of text in the middle line of a file. I have counted the lines in the file, and then I divide it into 2, after that I am stuck on how am I suppose to append the line on that file? When I tried to use this command 'second line >> filename' it appends it at... (3 Replies)
Discussion started by: felixwhoals
3 Replies

2. Shell Programming and Scripting

Simple AWK script problem.

Hi all, I have set up a simple awk script to calculate the average of values that are printed out a number of times per second (the number of time the printing occurs varies). The data is of the format shown below: 1 4.43 1 3.65 1 2.45 2 7.65 2 8.23 2 5.65 3 4.65 3 6.21 .. .. 120... (4 Replies)
Discussion started by: omnomtac
4 Replies

3. Shell Programming and Scripting

awk gsub simple problem

Hi New to shell script and awk and need assistance on this problem. I need to use a variable to substitute a string in an external file and write the changed info to another file. At first I did not know if you could use a variable as the sub value but the following showed me that I can. ... (3 Replies)
Discussion started by: hukcjv
3 Replies

4. Shell Programming and Scripting

simple awk problem

pcn linus> ntpq -p remote refid st t when poll reach delay offset disp ============================================================================== +smpnn01 ntpsrv1 2 u 829 1024 377 1.46 0.793 0.85 *smpnn02 ntpsrv1 2 u ... (2 Replies)
Discussion started by: arch12
2 Replies

5. Shell Programming and Scripting

Please help me with a simple problem

Hi, I have a very simple script like below: for n in 10 20 30 do for a in 30 40 50 60 70 80 do for r in 2 3 4 5 6 7 do m=$((r*a)) count=1 while do echo "a = " $a ", m = " $m ", n = " $n ... (2 Replies)
Discussion started by: Dark2Bright
2 Replies

6. Shell Programming and Scripting

Simple awk problem II

Hello; Trying to figure out how to keep just the contents between the two search lines: awk '/regexp_1/ ,/regexp_2/' I do not want lines containing regexp_1 and regexp_2 in the output. Thank you for any ideas Video tutorial on how to use code tags in The UNIX and Linux Forums. (5 Replies)
Discussion started by: delphys
5 Replies

7. Shell Programming and Scripting

another simple awk problem

Hello; I need to print two previous lines after searching for a reg exp: awk '/haywood/' should produce the following =================== p9J46THe020804 89922 Tue Oct 18 21:06 MAILER-DAEMON (host map: lookup (haywood.com): deferred) ... (1 Reply)
Discussion started by: delphys
1 Replies

8. Shell Programming and Scripting

simple awk sort problem

Hello folks I have the following output UNIX95=1 ps -ef -o pcpu,user,pid,args |more %CPU USER PID COMMAND 0.03 root 0 swapper 0.08 root 1 init 0.00 root 13 net_str_cached 0.00 root 12 usbhubd 0.00 root 11 escsid 0.00 root 10... (3 Replies)
Discussion started by: delphys
3 Replies

9. Shell Programming and Scripting

simple wc problem

Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines peter paul john I run the command # var=`grep paul file.txt` # echo $var paul # echo $var | wc -l 1 but when I grep for a value that isnt in the file, i still... (4 Replies)
Discussion started by: rethink
4 Replies

10. Shell Programming and Scripting

Simple awk search problem

Hello; we have : awk '/reg_exp/,0/ prints every line after the first occurrence of "reg_exp" But if I want to print rest of the lines AFTER the last occurrence of "reg_exp", how would I do it ?? Tried : awk ' ! (/reg_exp/,0)' But it errored... Thank you for any... (5 Replies)
Discussion started by: delphys
5 Replies
SHLOCK(1)						      General Commands Manual							 SHLOCK(1)

NAME
       shlock - create lock files for use in shell scripts

SYNOPSIS
       shlock -p pid -f name [ -b ] [ -u ] [ -c ]

DESCRIPTION
       Shlock  tries  to  create  a  lock  file named name and write the process ID pid into it.  If the file already exists, shlock will read the
       process ID from the file and test to see if the process is currently running.  If the process exists, then the file will not be created.

       Shlock exits with a zero status if it was able to create the lock file, or non-zero if the file refers to currently-active process.

OPTIONS
       -b     Process IDs are normally read and written in ASCII.  If the ``-b'' flag is used, then they will be written as  a	binary	int.   For
	      compatibility with other systems, the ``-u'' flag is accepted as a synonym for ``-b'' since binary locks are used by many UUCP pack-
	      ages.

       -c     If the ``-c'' flag is used, then shlock will not create a lock file, but will instead use the file to see if the	lock  is  held	by
	      another  program.   If  the  lock  is  valid, the program will exit with a non-zero status; if the lock is not valid (i.e., invoking
	      shlock without the flag would have succeeded), then the program will exit with a zero status.

EXAMPLES
       The following example shows how shlock would be used within a shell script:
	      LOCK=/var/run/innd/LOCK.send
	      trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15
	      if shlock -p $$ -f ${LOCK} ; then
		  # Do appropriate work
	      else
		  echo Locked by `cat ${LOCK}`
	      fi

HISTORY
       Written by Rich $alz <rsalz@uunet.uu.net> after a description of HDB UUCP locking given by Peter Honeyman.  This  is  revision  1.9,  dated
       1996/10/29.

																	 SHLOCK(1)
All times are GMT -4. The time now is 07:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy