jack
jack

Reputation: 163

Unix help with files

I have two dat files that are created by script and stored in directory.. is there a way to find what is happening with the files after it is being created.. how can i find that out.. one more thing what command searches for particular word in all files in one directory i tried grep -r.. didnt work for me.. any other suggestion..

Upvotes: 0

Views: 68

Answers (4)

ghostdog74
ghostdog74

Reputation: 342453

Don't understand your first question. But for your 2nd question, to search for word in files in directory,

Pure shell solution

shopt -s nullglob
for file in *
do
  while read -r line
  do
     case "$line" in
        *searchword*) echo "$file: $line";;
     esac
  done < "$file"
done

Using grep

grep -l "pattern" *

Using awk

awk '/pattern/{print FILENAME": "$0}' *

Upvotes: 0

Heisenbug
Heisenbug

Reputation: 39174

For the second question:

find . | xargs grep word_to_search

It will list recursively all files from the current dir (.) . Then it gives them as input to grep.

For the first question: if you plained to constantly monitor the files changes, you may consider to use svn.

Upvotes: 0

cnicutar
cnicutar

Reputation: 182649

You can monitor the files using inotifywait(1).

inotifywait efficiently waits for changes to files

It is suitable for waiting for changes to files from shell scripts

Upvotes: 1

shellter
shellter

Reputation: 37288

I agree with others, the first part of your question is too vague. Why not add some detail like 'I expected the file to change like XXXX', how do I confirm that?'

You wrote

what command searches for particular word in all files in one directory

Just use plain grep, i.e.

cd myDataDir
grep 'searchTarget' *

I hope this helps.

P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

Upvotes: 0

Related Questions