Find string and Not find to particular string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find string and Not find to particular string
# 1  
Old 08-04-2011
Question Find string and Not find to particular string

Hi,

I need to find the word with numbers (alpha-num) like XYZ1234.
But the file has some **Result of XYZ1234** strings,which i dont want to take or omit.
how can search string and not that particular string?Smilie
after reading it to array,i searched

foreach $find(@array)
{
if ($find=~ m/string(\d+))
{
print $find
}
}

Thanks in Advance
# 2  
Old 08-04-2011
please provide the input format and output format

so, if the file has the below string

Code:
 
Result of XYZ1234

then you need the output as XYZ1234 only ?
# 3  
Old 08-04-2011
Hi itkamaraj,

I have some html file it contains table.In that i need to find string like "details" and print below lines which have XYZ1234.
But in file,some string "Results of XYZ1234" also which i don't want to take.

Thank You for reply
# 4  
Old 08-04-2011
still, u didnt give sample input file and output file
# 5  
Old 08-04-2011
In the find command use without use "!" option or "-not" option not to search for a particular string.

For example:
find . -name "*".pl -not -name "*".sh -type f

will list all the files ending with ".pl" and exlude all the files ending with ".sh"

For more understanding refer to the blog:
http://linux-forum-karthik.blogspot....name-and.html:)
# 6  
Old 08-04-2011
Code:
 
$ nawk ' /[A-Z][0-9]/ && ! /Results/ {print $0}' test
details XYZ1234
details XYZ1234
details XYZ1234
details XYZ1234

 
$ cat test
details XYZ1234
Results of XYZ1234
Results of XYZ1234
details XYZ1234
details XYZ1234
details XYZ1234
Results of XYZ1234

# 7  
Old 08-04-2011
Hi,

i have attached input and output file for your reference.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find previous string based on an input string?

Hi, I did some research but cannot find the right solution so hopefully someone can help me here. I have a long string format like: VAR=111:aaaa,222:bbb,333:ccc it could be VAR=111:aaa,222:bbb,333:ccc,444:ddd, etc what I looking for is eg. if I give ccc, it will return me 333... (2 Replies)
Discussion started by: netbanker
2 Replies

2. Shell Programming and Scripting

Find string in file and find the all records by string

Hello I would like to get know how to do this: I got a big file (about 1GB) and I need to find a string (for instance by grep ) and then find all records in this file based on a string. Thanks for advice. Martin (12 Replies)
Discussion started by: mape
12 Replies

3. Shell Programming and Scripting

Find a string and print all lines upto another string

Ok I would like to do the following file test contains the following lines. between the lines ABC there may be any amount of lines up to the next ABC entry. I want to grep for the filename.txt entry and print the lines in between (and including that line) up to and including the last line... (3 Replies)
Discussion started by: revaroo
3 Replies

4. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

5. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

6. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

7. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

8. Shell Programming and Scripting

Find a string in textfile, erase $num lines after that string

I have a textfile containing text similar to the following pattern: STRING1 UNIQUE_STRING1 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING2 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING3 STRING2 STRING3 (6 Replies)
Discussion started by: ilcsfe
6 Replies

9. Shell Programming and Scripting

[Perl] Find one string, change another string.

Hi, In principle I am searching for a Perl equivalent for this sed command: sed "/TIM_AM_ARGS=/ s/60/1440/" $EDIT_FILE > $TEMP_FILE cp $TEMP_FILE $EDIT_FILE I was wondering if it needs to be like this, or that there other, shorter, alternatives: open (TIMENVFILE, "<$timenvfile") or die... (5 Replies)
Discussion started by: ejdv
5 Replies

10. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies
Login or Register to Ask a Question