Finding a word with awk or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a word with awk or sed
# 1  
Old 06-14-2017
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; 06-14-2017 at 09:20 AM..
# 2  
Old 06-14-2017
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.
# 3  
Old 06-14-2017
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 06-14-2017
Code:
word="CUTAFAAQ" ; LISTE /tmp/RESS |  awk '$1=="EX" && $NF==w && $0=$NF' w="$word"

word can be set to whatever.
# 5  
Old 06-14-2017
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; 06-15-2017 at 07:09 AM..
# 6  
Old 06-14-2017
Find the second occurrence of "EX = " and print the last word
Code:
awk '($1=="EX" && $2=="=" && ++flag==2) {print $NF}'

# 7  
Old 06-14-2017
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; 06-15-2017 at 07:09 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retrieve information Text/Word from HTML code using awk/sed

awk/sed newbie here. I have a HTML file and from that file and I would like to retrieve a text word. <font face=arial size=-1><li><a href=/value_for_clients/Tokyo/abc_process.txt>abc</a> NDK Version: 4.0 </li> <font face=arial size=-1><li><a... (6 Replies)
Discussion started by: sk2code
6 Replies

2. Shell Programming and Scripting

sed / awk to get specific word in line

I have http log that I want to get words after specific "tag", this a sample line from the log: 98,POST,200 OK,www.facebook.com,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,/ajax/updatestatus.php?__a=1,datr=P_H1TgjTczCHxiGwdIF5tvpC; lu=Si1fMkcrU2SInpY8tk_7tAnw;... (6 Replies)
Discussion started by: erlanq
6 Replies

3. Shell Programming and Scripting

Extract word from text (sed,awk, etc...)

Hello, I need some help extracting the number after the RBA e.g 15911688 from the below block of text (e.g: grep RBA |sed .......). The code should be valid for blocks if text generated at different times as well and not for the below text only. ... (2 Replies)
Discussion started by: drbiloukos
2 Replies

4. Shell Programming and Scripting

making the first character of word using uppercase using awk and sed

I want to make the first character of some words to be uppercase. I have a file like the one below. uid,givenname,sn,cn,mail,telephonenumber mattj,matt,johnson,matt johnson,mattj@gmail.com markv,mark,vennet,matt s vennet,markv@gmail.com mikea,mike,austi,mike austin,mike@gmail.com I want... (3 Replies)
Discussion started by: matt12
3 Replies

5. Shell Programming and Scripting

sed or awk to print 2nd last word

Hi, I have a file which has the following /usr/new/xyz/abc /us1/neb/yxr/def /usr/bin/cloud1/fgh /net/bin1/txt1/kdq I want to do something like this /usr/new/xyz/abc xyz /us1/neb/yxr/def yxr /usr/bin/cloud1/fgh cloud1 /net/bin1/txt1/kdq txt1 I need to add the 2nd last word to the... (3 Replies)
Discussion started by: matbrow
3 Replies

6. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

7. Shell Programming and Scripting

Question on awk for finding the column number using a match word

Hi Guys, Please help me out in my situation of writing a shell script Exampl:I have a output like asnapply 1 2 3 apply_server=1 apply_schema=ASN asnapply 1 2 3 apply_server=2 apply_schema=ASN Now i need output like asnacmd applysever=1 applyschema=ASN stop asnacmd applysever=2... (16 Replies)
Discussion started by: mallak
16 Replies

8. Shell Programming and Scripting

Getting the first word using sed,awk or perl

Input: root:x:0: daemon:x:1: bin:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mail:x:8: Output: root daemon bin sys adm tty (8 Replies)
Discussion started by: cola
8 Replies

9. Shell Programming and Scripting

Sed or awk cut all lines after word

Hi, sorry for newbie question :confused: can't find how to cut ? from 1000 2000 word some text1.... 100 200 300 word some text2.... 10 20 30 abc word some text3.... to some text1.... some text2.... some text3.... (7 Replies)
Discussion started by: Trump
7 Replies

10. Shell Programming and Scripting

awk or sed for finding closest pattern to a line number

hi guys, I want to do pattern matching with awk or sed but I don't know how. here's what I want: I have a line number for a pattern that I have already found using grep, and I know a pattern like "---" that happens a few lines above that certain line number. I want to print out the chunk... (1 Reply)
Discussion started by: alirezan
1 Replies
Login or Register to Ask a Question