Note that you said that you wanted the output:
but you said you wanted to match ABC_; not ABS_ and ABS_ does not appear in your sample input.
If the strings you want to match could contain characters that have special meanings in regular expressions or if you want varying strings with different invocations of your script, here is a way to do it using awk:
As shown, this script will only print one occurrence of each matched word. If you delete the lines shown in red, it will print every occurrence of each matched word. (Your sample input didn't contain duplicates of any words starting with the strings to be matched, but if you duplicate the input, you'll see the difference.)
As always, if you want to try this on a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.
Thanks Elixir and Don for the help, the code is working perfectly fine.
I apologise for my mistake Don, it should be ABC_ or ADF_. But i got your point too.
I have a file with a list of references towards the end and want to apply a grep for some string.
text ....
@unnumbered References
@sp 1
@paragraphindent 0
2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez,
Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
hi I made this simple script to extract data and pretty much is a list and would like to extract data of two words separated by commas and I would like to make a new text file that would list these extracted data into a list and each in a new line.
Example that worked for me with text file... (5 Replies)
Hi
This is my first post and I'm just a beginner. So please be nice to me.
I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file?
I have tried sed -n 241,241p... (13 Replies)
i need to extract the string between two tags,
input file is
<PersonInfoShipTo AddressID="446311709" AddressLine1="" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper="" City="" Company="" Country="" DayFaxNo="" DayPhone="" Department=""... (5 Replies)
Hi there, Unix Gurus
Working with big listings of english sentences for my pupils, of the type:
1. If the boss's son had been , someone would have asked for money by now.
2. Look, I haven't a crime, so why can't you let me go?
....
I wondered how to extract the words between brackets in... (7 Replies)
Hi Guys,
While I was writing one shell script , I just got struck at this point.
I need to extract words from a file at some specified position and do some comparison operation and need to replace the extracted word with another word.
Eg : I like Orange very much.
I need to replace... (19 Replies)
Hi all,
I would like to print words in a file seperated by whitespaces containing a specific pattern like "="
e.g. I have a file1 containing strings like
%cat file1
The= some= in
wish= born
<eof> .I want to display only those words containing = i.e The= , some=,wish=
... (5 Replies)
Couldn't find much help on the kind of question I've here:
There is this text file with text as:
Line one has a bingo
Line two does not have a bingo but it has a tango
Bingo is on line three
Line four has both tango and bingo
Now I would want to search for the pattern "bingo" in this file... (3 Replies)
Sir,
I want to check for the repation of a user address in a file i used || as my delimiter and want to check repetaip0n of the address that is mailid and then i have to use IMAP and all.
How can i do this...
I am in linux ...and my file is linux file.
... (5 Replies)