How to find a word in a all the files in a Directory??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find a word in a all the files in a Directory??
# 1  
Old 09-30-2008
Error How to find a word in a all the files in a Directory??

I want to find a specific word present in all the files ina directory....Please tell me the command to be used??

Thanks
# 2  
Old 09-30-2008
Code:
grep <word to be searched> <path of the directory or *(if running from the directory)>

# 3  
Old 09-30-2008
Hi,

Try this out.
[code]
find . -type f -exec grep -i searchstring \{\} filename;
[\code]
# 4  
Old 10-03-2008
Error Thank you and one more question

print "count,pub,prodline,group,sector,date,source" > $fname

cat sp_log.summary.$firstday-$lastday.ProdlineSector | sed "s/^ *//g;s/ *$//g" >sp_log.summary.$firstday-$lastday

cat sp_log.summary.$firstday-$lastday | sed "s/$/ $lastyy-$lastmm cache/;s/ /,/g" >> $fname

cat $fname | sed "s/NULL//g" >$fname.new


THIS is the part of a shell script which creates a .CSV file.

Now for the data under pub field, i want to inset a ' in front of the data getting inserted.

Can someone please help??Smilie
# 5  
Old 10-03-2008
Replace the last command with something like

Code:
sed -e 's/NULL//g' -e "2,\$s/,/,'/" $fname >$fname.new

This adds a single quote immediately after the first comma, except on the first line. Take out the 2,\$ prefix if you want it on the first line, too.

All the other occurrences of cat are Useless, too; sed is perfectly capable of reading from a named file all by itself.
# 6  
Old 10-03-2008
Query

Thank you, i will check it out...

1 more query i had, in the first question, the grep method worked, Thanks

But if i want to get the results page vise what is the command??
sibce it scrolls down and i am nto able to note anything

Thanks All for your help!!!Smilie
# 7  
Old 10-04-2008
Code:
commandwithlotsofoutput | less

... or "more" if you don't have less. (Or "pg" if you have neither, but then you probably don't have a web browser either.)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies

2. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

3. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

4. Shell Programming and Scripting

Find word in a directory files

Hi folks, i have a file in which i have words like below words.txt(file name) and words are arranged likes no spaces between words Apple Banana Carrot And i have list files which have these words in a directory (/tmp/satemp) test1.txt test2.txt test3.txt So if the word 'Apple' is... (3 Replies)
Discussion started by: coolboy98699
3 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Shell Programming and Scripting

How can i find a word inside a file from a directory and it's subdirectory ?

Suppose i have a word "mail". I have to search this word in all files inside a directory and it's sub-directories. It will also search in all hidden directory and sub-directories. If it finds this word in any file it will list that file. How can i do this with perl/ruby/awk/sed/bash or... (9 Replies)
Discussion started by: cola
9 Replies

7. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

8. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

9. Shell Programming and Scripting

Shell:Find a word in files in a directory and subdirectories

I'm looking to write a ksh code with will be alble to find a word like 'toto' in all files going from my current directory. eg. /doc ----------->have: text.c which "toto" /doc/usr-------->have: build.pc, help.java which "toto" /doc/usr/cach -->have: test.sh which "toto" /doc/build... (4 Replies)
Discussion started by: yeclota
4 Replies

10. UNIX for Dummies Questions & Answers

search for certain word in a files from directory

hi can i know how to get the file name of any files containing for example "abc" from a number of files in a directory? i tried "ls -ltrc | grep abc" but no resulted generated. thanks in advance. (1 Reply)
Discussion started by: legato
1 Replies
Login or Register to Ask a Question