L
L
Lexaband2017-05-30 13:03:18
linux
Lexaband, 2017-05-30 13:03:18

Is it possible to do this in bash, and if so, how?

We need a bash script that for all files in the temporary directory that were created for the current month and did not change during the week, when the test line is in them, it will change it to tset.
Help me please. I want to understand the point.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
romy4, 2017-05-30
@romy4

well, here it is definitely find with its search parameters and -exec

C
CityCat4, 2017-05-30
@CityCat4

The point is very simple.
Take the current date, calculate a range equal to a week (date can do this)
Find all files with a creation date such and such and a modification date no greater than such and such (find can do this)
And for each of them perform a search-and-replace (sed can do this ) ), well, for aesthetics, you can first grep the desired line, if not, do not call sed.
bash is needed here just to bring it all together.

V
Victor Taran, 2017-05-30
@shambler81

In general, this is not possible! ;(
At least since the file system does not store the creation time ;((((((
Only available

Changed:
Moduvied:
Accessed:

As we can see, oddly enough, there is no creation here.
However, what can we do:
find .search from the current folder and below recursively.
-type fonly files
-mtime -7 modified in the last seven days.
-exec Команда {}" \;execute the command with the found file (loop)
sed -i 's/test2/test21/g- find the line test and replace it with test21
Describe what problem you are trying to solve, most likely you need something else.
Also look at patch or diffharder but it will suit you for suregit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question