Sponsored Content
Top Forums Shell Programming and Scripting Searching multiple patterns using awk Post 302831973 by kcboy on Friday 12th of July 2013 10:35:24 PM
Old 07-12-2013
Quote:
Originally Posted by RudiC
Please use code tags as required by forum rules!

You are using an address range with an "open" (unset) end, which should work fine given it will start, which it can't, as qh1adm is never found. Once it started, it won't stop until its ending condition is met, so you'd need an if clause in the action section. Sth like
Code:
awk "/$STOPMARK/,0 {if ($0 ~ /QH1/) print}" file

(untested! You may need to escape the slashes) might work, if the datetime field is sorted. Try also
Code:
awk -v SM=$STOPMARK '/QH1/ && $2 >= SM' file


Hello RudiC,

Thank you very much for your prompt reply. I tried the following:

Code:
awk "/$STOPMARK/,0 {if ($1 ~ /qh1adm/) print}" logfile

$STOPMARK has 20130709213321

Thanks.

---------- Post updated at 06:31 AM ---------- Previous update was at 06:25 AM ----------

Quote:
Originally Posted by RudiC
Please use code tags as required by forum rules!

You are using an address range with an "open" (unset) end, which should work fine given it will start, which it can't, as qh1adm is never found. Once it started, it won't stop until its ending condition is met, so you'd need an if clause in the action section. Sth like
Code:
awk "/$STOPMARK/,0 {if ($0 ~ /QH1/) print}" file

(untested! You may need to escape the slashes) might work, if the datetime field is sorted. Try also
Code:
awk -v SM=$STOPMARK '/QH1/ && $2 >= SM' file


Hello RudiC,

Code:
 
awk -v SM=$STOPMARK '/qh1adm/ && $2 >= SM' logfile

worked.

Thanks again.

---------- Post updated at 06:41 AM ---------- Previous update was at 06:31 AM ----------

Quote:
Originally Posted by Yoda
Variable expansion doesn't happen inside single quote. So define an awk variable and use that instead:
Code:
awk -v S="$STOPMARK" '$2 >= S && /qh1adm/' logfile


Hello Yoda,

The above command works perfectly! Thank you very much for your help.

---------- Post updated at 07:35 PM ---------- Previous update was at 07:41 AM ----------

Hello RudiC, Hello Yoda,

Now I am getting the desired output:

Code:
 
qh1adm 20130711151154 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ
qh1adm 20130711151155 : tp import all QH1 u6 -Dsourcesystems=E7B,B17
qh1adm 20130711151200 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ

I was just wondering how to assign this output to an array. The reason is I want to count how many records are returned. Thanks a lot for your help.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AWK: Multiple patterns per line

Hi there, We have been given a bit of coursework using awk on html pages. Without giving too much away and risking the wrath of the plagerism checks, I can say we need to deal with certain html elements. There may be several of these elements on one line. My question is, if there are more... (1 Reply)
Discussion started by: Plavixo
1 Replies

2. Shell Programming and Scripting

Searching for multiple patterns in files

I have a situation where I need to search for multiple strings (error messages) such as 'aborted' 'file not found' etc in directory having logs. I have put all the error messages in a text file and using the command. grep -f <textfile> <filetobegrepped> I'm doing this thru a script where I... (5 Replies)
Discussion started by: bornon2303
5 Replies

3. Shell Programming and Scripting

Searching for multiple patterns in a file

Hi All, I have a file in which i have to search for a pattern from the beginning of the file and if the pattern is found , then i have to perform a reverse search from that line to the beginning of the file to get the first occurrence of another pattern. sample input file hey what are you... (8 Replies)
Discussion started by: Kesavan
8 Replies

4. Shell Programming and Scripting

Awk script searching patterns issue

Hi I am having a file like this FILE1 ##################### C16ROTINV_ REFCLK_RXL RXBCLK32_R REFCLK_TXL CLK8_TXLIN RXBCLK32_R DCLK_TXLIN CLK32D_TXL RXACLK32_R ##################### (3 Replies)
Discussion started by: jaita
3 Replies

5. Shell Programming and Scripting

searching multiple patterns in perl

Hi, I have code like: Output it is comming as: Rels: WM2 Rels: WG2 Rels: 5 - pre/prods.pl Rels: 6 Rels: 7 Rels: 8 Rels: 10 Rels: Int But i want only "Rels: 5" pattern Just above "- pre/prods.pl". By... (7 Replies)
Discussion started by: Anjan1
7 Replies

6. Shell Programming and Scripting

[Solved] HP-UX awk sub multiple patterns

Hi, I am using sub to remove blank spaces and one pattern(=>) from the input string. It works fine when I am using two sub functions for the same. However it is giving error while I am trying to remove both spaces and pattern using one single sub function. Working: $ echo " OK => " |awk... (2 Replies)
Discussion started by: sai_2507
2 Replies

7. Shell Programming and Scripting

Multiple patterns for awk script

Hi, I'm getting stuck when supplying multiple patterns for the below code: awk -F, ' .. .. if ($0 ~ pattern) { .. .. } .. .. ' pattern='$ROW' input_file for the same code I'm trying to supply multiple patterns as given below: awk -F, ' .. .. if( ($0 ~ pattern) && ($0 ~... (6 Replies)
Discussion started by: penqueen
6 Replies

8. Shell Programming and Scripting

Replacing multiple line patterns with awk

Hi forum, Can you please help me understand how to look for and replace the below pattern (containing line breaks) and return a new result? Rules: Must match the 3 line pattern and return a 1 line result. I have found solutions with sed, but it seems that sed installed in my system is... (5 Replies)
Discussion started by: demmel
5 Replies

9. Shell Programming and Scripting

Check multiple patterns in awk

I need to check if 2 values exists in the file and if they are equal print 0. output.txt: ------------ 1 2 3 4 5 6 Inputs: a=1 b=2 My pattern matching code works but I am trying to set a counter if both the pattern matches which does not work.If the count > 0,then I want to... (3 Replies)
Discussion started by: kannan13
3 Replies

10. Shell Programming and Scripting

Searching multiple patterns and construct SQL

Hello, I have attached 2 files 1) Original_table_definition.txt => which has definition of 3 tables 2) describe_table_output.txt => which has again 3 tables definition gotten thorugh doing a show table or describe table way. Now difference between 3 tables are that tablea has no... (2 Replies)
Discussion started by: nv186000
2 Replies
All times are GMT -4. The time now is 02:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy