Finding a word through substring in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Finding a word through substring in a file
# 1  
Old 07-01-2019
Finding a word through substring in a file

I have a text file that has some data like:
Code:
PADHOGOA1 IOP055_VINREG5_1 ( .IO(VINREG5_1), .MONI(), .MON_D(px_IOP055_VINREG5_1_MON_D), .R0T(px_IOP054_VINREG5_0_R0T), .IO1() );

PADV30MA0 IOP056_VOUT3_IN ( .IO(VOUT3_IN), .V30M(px_IOP056_VOUT3_IN_V30M));

PADV30MA0 IOP057_VOUT3_OUT ( .IO(VOUT3_OUT), .V30M(px_IOP057_VOUT3_OUT_V30M) );

PADV15MA0 IOP059_VOUT15_OUT ( .IO(VOUT15_OUT), .V15M(px_IOP059_VOUT15_OUT_V15M) );

PADHOGOA1 IOP064_VREFLB ( .IO(VREFLB), .MONI(), .MON_D(px_IOP064_VREFLB_MON_D), .R0T(px_IOP064_VREFLB_R0T), .IO1() );

My substring is .V30M
I am find this substring and want to display the whole word.

Desired output:
Code:
.V30M(px_IOP057_VOUT3_OUT_V30M)

Please need some help.

Last edited by Scrutinizer; 07-01-2019 at 02:55 PM.. Reason: quote tags -> code tags; + extra code tags
# 2  
Old 07-01-2019
Why doesn't .V30M(px_IOP056_VOUT3_IN_V30M)) show up in your desired output? Try
Code:
grep -o "[[:alnum:]]*\.V30[[:alnum:]()_]*" file
.V30M(px_IOP056_VOUT3_IN_V30M))
.V30M(px_IOP057_VOUT3_OUT_V30M)

This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-01-2019
Or try:
Code:
grep -o '\.V30M([^)]*)' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding pattern in a text file and returning a part of the word

Dear All, assume that we have a text file or a folder of files, I want to find this pattern followers*.csv in the text file , and get * as the output. There are different matches and * means every character. Thank you in advance. Best, David (1 Reply)
Discussion started by: davidfreed
1 Replies

2. Shell Programming and Scripting

Bash - Extracting whole word containing substring

hello. I get this text when using some command : S | Name | Type | Version | Arch | Repository --+-----------------+---------+---------+------+------------- | AdobeReader_enu | package | 9.5.4-1 | i486 | zypper_local I need to get "AdobeReader_enu" from the the pattern "Ado"... (7 Replies)
Discussion started by: jcdole
7 Replies

3. Shell Programming and Scripting

AWK Substring without cutting off word

Can someone help me to make this code without cutting off words ni the string? awk '{for(i=1;i<length;i+=100) print substr($0,i,100)}' Thank you! (4 Replies)
Discussion started by: sanantonio7777
4 Replies

4. Shell Programming and Scripting

Finding duplicates from positioned substring across lines

I have million's of records each containing exactly 50 characters and have to check the uniqueness of 4 character substring of 50 character (postion known prior) and report if any duplicates are found. Eg. data... AAAA00000000000000XXXX0000 0000000000... upto50 chars... (2 Replies)
Discussion started by: gapprasath
2 Replies

5. Shell Programming and Scripting

Finding longest common substring among filenames

I will be performing a task on several directories, each containing a large number of files (2500+) that follow a regular naming convention: YYYY_MM_DD_XX.foo_bar.A.B.some_different_stuff.EXT What I would like to do is automatically discover the part of the filenames that are common to all... (1 Reply)
Discussion started by: cmcnorgan
1 Replies

6. Shell Programming and Scripting

need help with finding a word in file's contents

Hi, I need to check if a particular name is already in the file or not and i am using following code for this... match=$(grep -n -e "$output1" outputfiles.txt ) where output1 is the variable name having names in it and outputfiles.txt is the file name ..and i am using ksh can anybosy... (6 Replies)
Discussion started by: manmeet
6 Replies

7. Shell Programming and Scripting

Finding a word in a file

Hi frndz, i have a flat file like, xxx yyy zzz sss aaa bbb yyy xxx rrr sss ttt yyy ddd zzzz cccc.. look, in this file i want to fetch the substring from one yyy to another one and need to print it then from next values between yyy's.. can you please give me some inputs on this.. ... (10 Replies)
Discussion started by: smr_rashmy
10 Replies

8. Shell Programming and Scripting

help for shell script of finding shortest substring from given string by user

please give me proper solution for finding a shortest substring from given string if string itself and first char and last char of that substr are also given by user if S="dpoaoqooroo" and FC="o" and LC="o",then shortest substr is "oo" and rest of the string is "dpoaoqroo" i have code but it is... (1 Reply)
Discussion started by: pankajd
1 Replies

9. Shell Programming and Scripting

finding the last substring...

hii, i want to know the shell command for finding the last occurance of a substring in string.. i can use grep command or sed to find out the occurance of a substring in a string but how do i find out the last occurance.shud i use grep amd and cut the string everytime and store it in a new... (7 Replies)
Discussion started by: cutelucks
7 Replies

10. Shell Programming and Scripting

Finding word in file then print the preceding....

Hi, I am looking for a way to find a particular word in a file then print a line that precedes this line, as well as this line. Sometimes in a log file there is only one word per line and I need to print one of the lines leading up to the single worded line. Example - I can grep for ouch... (5 Replies)
Discussion started by: g_jumpin
5 Replies
Login or Register to Ask a Question