Need to find a string in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to find a string in files
# 1  
Old 04-27-2011
Need to find a string in files

Hi,

I have a directory nsk,
files a.sql, b.sql, c.sql, d.sql,

assuming that I have line 'INSERT ALL INTO abc' in a.sql and c.sql

I need to list a filename, line number and complete line which contains ''INSERT ALL INTO abc' irrespective of case.

also in my files mentioned 'INSERT ALL INTO abc' may be splitted into 4 lines/3 lines i.e., it may not be in single line

'INSERT ALL INTO abc' can be present as 'INSERT
ALL INTO abc'
'INSERT ALL INTO abc' can be present as 'INSERT ALL
INTO
abc'

So, please provide me the command which gives the above command satisfying the above requirements,


Thanks for your help in advance,
# 2  
Old 04-27-2011
smthg like

Code:
grep -ni 'INSERT ALL INTO abc' ./nsk/?.sql

# 3  
Old 04-27-2011
Try this one, sed script:

Code:
 
/[Ii][Nn][Ss][Ee][Rr][Tt]/,/[Aa][Bb][Cc]/{ =
p
}

# 4  
Old 04-27-2011
I didn't get anyoutput in that case
# 5  
Old 04-27-2011
Do you have table names as "abc"? The above sed script should print lines between Insert and abc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find all .sh files in file system and need to replace the string inside .sh files

Hi All, I need to write a script to find all "*.sh" files in /home file system and if any string find "*.sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this. find / -name... (3 Replies)
Discussion started by: bhas85
3 Replies

2. Shell Programming and Scripting

Find a string in all files and echo a message

Hi. I m trying to figure out how to do this. I have a directory full of files (100 files) and I want to be able to search for a string called "end" at the end of the files (last line or last 5 lines) and echo each file to say "incomplete" if not found. This is what I have so far. ---... (4 Replies)
Discussion started by: jasonhawaii
4 Replies

3. Ubuntu

Trying to find files on a system that contain a certain string

I have tried just about every find and grep command possible and I cannot find these damn files!! This is the problem: On the node you just swapped in, there are 5 JPEG files whose names contain the word "intro" in some form. Find all five files from on the entire disk (i.e. from root /). ... (2 Replies)
Discussion started by: dukeu69
2 Replies

4. Shell Programming and Scripting

find duplicate string in many different files

I have more than 100 files like this: SVEAVLTGPYGYT 2 SVEGNFEETQY 10 SVELGQGYEQY 28 SVERTGTGYT 6 SVGLADYNEQF 21 SVGQGYEQY 32 SVKTVLGYEQF 2 SVNNEQF 12 SVRDGLTNSPLH 3 SVRRDREGLEQF 11 SVRTSGSYEQY 17 SVSVSGSPLQETQY 78 SVVHSTSPEAF 59 SVVPGNGYT 75 (4 Replies)
Discussion started by: xshang
4 Replies

5. UNIX for Dummies Questions & Answers

Using grep to find files that don't contain a string

Hi all, I am still learning my way around unix commands and I have the following question. I have a website and I want to search for all the html pages that don't contain a certain js file. The file I am searching for is located under /topfolder/js/rules.js . So I assume in my grep search I... (5 Replies)
Discussion started by: SyphaX
5 Replies

6. Shell Programming and Scripting

Help to find string and return following characters from list of files

Hi, I'm fairly new to UNIX, but hopefully some-one can help me with this: I am using the following code to find files with the name "example.xml": find . -name "example.xml" -print that would print me a list like the example here: ./dir1/dir2/example.xml... (5 Replies)
Discussion started by: boijie
5 Replies

7. Shell Programming and Scripting

How to find particular string in multiple files

Hello friends, I have find a paticular string from the files present in my user for example: a username and password is hardcoded in multiple files which present in the my user.so I have to search about username in which files it is available.there are several dirctories are there,so... (5 Replies)
Discussion started by: sivaranga001
5 Replies

8. Shell Programming and Scripting

find and replace string in a directory files

Hi, I have a directory has DIR1 and the D1 directory has 200+ files. I want change the string from "Bangalore" to "Bangaluru" in all files in the D1 directory. Thanks (2 Replies)
Discussion started by: koti_rama
2 Replies

9. Shell Programming and Scripting

How to find a string inside files

Hi, I would like to know how to get a list of files that contain a specific string inside them. Thanks (12 Replies)
Discussion started by: yoavbe
12 Replies

10. UNIX for Dummies Questions & Answers

Find and replace a string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (2 Replies)
Discussion started by: pharos467
2 Replies
Login or Register to Ask a Question