Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Finding a word with awk or sed

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago
sam01 sam01 is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 16 June 2017, 5:40 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Finding a word with awk or sed

Hello,
in a AIX system : AIX CDRATE01 2 7 00FAB3114C00

my following commande give the result :

LISTE /tmp/RESS


Code:
 
****************************************************************
 
Liste
TYPE = XXXXXXX
 
        EX        =                                        YYYY
        VER	  =                                            S
        DATE      =                                     20160601
        HEURE     =                                       134701
 
        EX        =                                     CUTAFAAQ
        VER       =                                            X
        DATE      =                                     20160601
        HEURE     =                                       134701
 
****************************************************************

i would like to find that word : CUTAFAAQ

But this word is can change.

So how could i know this string ?

I tested this but it doesn't work :


Code:
LISTE /tmp/RESS|awk '/EX *=/ && ++flag { FS="=" ; $0=$NF ; FS=" " ; $0=$NF } flag==2 && ++flag'

or


Code:
LISTE /tmp/RESS|sed -n '1{x;s/.*/x/;x};/EX[[:space:]=]*/{x;s/x//;x;t;s/.*[[:space:]]//p;q}'

Thank's for your help

Last edited by jim mcnamara; 1 Week Ago at 08:20 AM..
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 27 June 2017, 8:38 AM EDT
Location: NM
Posts: 11,095
Thanks: 537
Thanked 1,068 Times in 990 Posts
Both of these will find the word:

Code:
awk '/CUTFAAQ$/ {print}' inputfilename
# or
awk '$3 =="CUTFAAQ" && $1=="EX"  {print}' inputfilename

If this is not the case please give us examples of how CUTFAAQ exists and is not as it appears.
in your code.
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago
sam01 sam01 is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 16 June 2017, 5:40 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Hello, i can't use the word : CUTAFAAQ because, as i said, this word is not the same each time... It often change, that's why it's quite complicated...
    #4  
Old Unix and Linux 1 Week Ago
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 26 June 2017, 5:55 PM EDT
Location: Houston, Texas, USA
Posts: 927
Thanks: 0
Thanked 311 Times in 296 Posts

Code:
word="CUTAFAAQ" ; LISTE /tmp/RESS |  awk '$1=="EX" && $NF==w && $0=$NF' w="$word"

word can be set to whatever.
Sponsored Links
    #5  
Old Unix and Linux 1 Week Ago
sam01 sam01 is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 16 June 2017, 5:40 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thank's but i don't know the tring the in advance...
i just want to find the string, whetever it is. But before the comand :


Code:
LISTE /tmp/RESS

i can't know which will be the string. I juste his plance is always the same.

Last edited by RudiC; 1 Week Ago at 06:09 AM..
Sponsored Links
    #6  
Old Unix and Linux 1 Week Ago
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 27 June 2017, 2:26 PM EDT
Location: Simplicity
Posts: 3,582
Thanks: 282
Thanked 1,191 Times in 1,077 Posts
Find the second occurrence of "EX = " and print the last word

Code:
awk '($1=="EX" && $2=="=" && ++flag==2) {print $NF}'

Sponsored Links
    #7  
Old Unix and Linux 1 Week Ago
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 June 2017, 4:40 PM EDT
Location: Aachen, Germany
Posts: 10,965
Thanks: 280
Thanked 3,371 Times in 3,104 Posts
If you don't know the word in advance, you need to define some context by which the target is identifyable, like "it's in the line starting with "EX" in the second block", or "it's on the fifth data line". You can't use "it's the last field that is 8 chars long" as this will cause false triggers...

Last edited by RudiC; 1 Week Ago at 06:09 AM..
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding total count of a word. mahesh1987 Shell Programming and Scripting 6 04-02-2013 03:55 AM
Finding a specific word rpatty Shell Programming and Scripting 16 11-26-2010 10:12 AM
Getting last 50 lines after finding a word pssandeep Emergency UNIX and Linux Support 9 12-01-2009 04:57 PM
need help with finding a word in file's contents manmeet Shell Programming and Scripting 6 10-01-2008 02:21 PM
Finding a word in a file smr_rashmy Shell Programming and Scripting 10 02-13-2008 01:02 AM



All times are GMT -4. The time now is 04:47 PM.