How to get filenames when using find and sed
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified.
This is how I am finding and then using sed:
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec sed -i -e "s/"str1"/"str2"/g" +
How do I print the file name of the changed files? I would like to print it in a sorted order so it's easier to read.
When using only sed we can do this:
sed -i 's/$pattern/$new_pattern/w changelog.txt' $filename
if [ -s changelog.txt ]; then
# CHANGES MADE, DO SOME STUFF HERE
else
# NO CHANGES MADE, DO SOME OTHER STUFF HERE
fi
But how do I do this when using find and sed together? I checked the man page and tried a bunch of stuff but nothing worked.
bash shell-script sed find
 |Â
show 3 more comments
up vote
3
down vote
favorite
I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified.
This is how I am finding and then using sed:
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec sed -i -e "s/"str1"/"str2"/g" +
How do I print the file name of the changed files? I would like to print it in a sorted order so it's easier to read.
When using only sed we can do this:
sed -i 's/$pattern/$new_pattern/w changelog.txt' $filename
if [ -s changelog.txt ]; then
# CHANGES MADE, DO SOME STUFF HERE
else
# NO CHANGES MADE, DO SOME OTHER STUFF HERE
fi
But how do I do this when using find and sed together? I checked the man page and tried a bunch of stuff but nothing worked.
bash shell-script sed find
I'm not exactly sure what you're trying to achieve, can you show a list of files, and what output you're expecting to see.
â EightBitTony
Jan 21 '16 at 14:49
@EightBitTony I have added examples, please take a look
â KLMM
Jan 21 '16 at 17:05
1
You just add-print
after your-exec
, it will only be executed if the-exec
was successful e.g.find . -type f ( -name *.git -o -name *.txt ) -exec sed -i 'blah_blah' ; -print
. Sure, you'll have to sort the output then.
â don_crissti
Jan 21 '16 at 18:11
@don_crissti using print giving an error "-print: command not found".
â KLMM
Jan 21 '16 at 18:34
1
Ah, yes,sed -i
is dumb and will "edit" the file even if nothing changes and report success... Add a-exec grep -q str1 ;
before the existing-exec sed...
That should do. Oh, and next time you reply, make sure you prepend my username with @ so the system notifies me e.g. @don_crissti otherwise I'll never know you replied (I just happened to return here)
â don_crissti
Jan 23 '16 at 2:45
 |Â
show 3 more comments
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified.
This is how I am finding and then using sed:
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec sed -i -e "s/"str1"/"str2"/g" +
How do I print the file name of the changed files? I would like to print it in a sorted order so it's easier to read.
When using only sed we can do this:
sed -i 's/$pattern/$new_pattern/w changelog.txt' $filename
if [ -s changelog.txt ]; then
# CHANGES MADE, DO SOME STUFF HERE
else
# NO CHANGES MADE, DO SOME OTHER STUFF HERE
fi
But how do I do this when using find and sed together? I checked the man page and tried a bunch of stuff but nothing worked.
bash shell-script sed find
I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified.
This is how I am finding and then using sed:
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec sed -i -e "s/"str1"/"str2"/g" +
How do I print the file name of the changed files? I would like to print it in a sorted order so it's easier to read.
When using only sed we can do this:
sed -i 's/$pattern/$new_pattern/w changelog.txt' $filename
if [ -s changelog.txt ]; then
# CHANGES MADE, DO SOME STUFF HERE
else
# NO CHANGES MADE, DO SOME OTHER STUFF HERE
fi
But how do I do this when using find and sed together? I checked the man page and tried a bunch of stuff but nothing worked.
bash shell-script sed find
bash shell-script sed find
edited Jan 22 '16 at 23:43
asked Jan 21 '16 at 14:31
KLMM
59119
59119
I'm not exactly sure what you're trying to achieve, can you show a list of files, and what output you're expecting to see.
â EightBitTony
Jan 21 '16 at 14:49
@EightBitTony I have added examples, please take a look
â KLMM
Jan 21 '16 at 17:05
1
You just add-print
after your-exec
, it will only be executed if the-exec
was successful e.g.find . -type f ( -name *.git -o -name *.txt ) -exec sed -i 'blah_blah' ; -print
. Sure, you'll have to sort the output then.
â don_crissti
Jan 21 '16 at 18:11
@don_crissti using print giving an error "-print: command not found".
â KLMM
Jan 21 '16 at 18:34
1
Ah, yes,sed -i
is dumb and will "edit" the file even if nothing changes and report success... Add a-exec grep -q str1 ;
before the existing-exec sed...
That should do. Oh, and next time you reply, make sure you prepend my username with @ so the system notifies me e.g. @don_crissti otherwise I'll never know you replied (I just happened to return here)
â don_crissti
Jan 23 '16 at 2:45
 |Â
show 3 more comments
I'm not exactly sure what you're trying to achieve, can you show a list of files, and what output you're expecting to see.
â EightBitTony
Jan 21 '16 at 14:49
@EightBitTony I have added examples, please take a look
â KLMM
Jan 21 '16 at 17:05
1
You just add-print
after your-exec
, it will only be executed if the-exec
was successful e.g.find . -type f ( -name *.git -o -name *.txt ) -exec sed -i 'blah_blah' ; -print
. Sure, you'll have to sort the output then.
â don_crissti
Jan 21 '16 at 18:11
@don_crissti using print giving an error "-print: command not found".
â KLMM
Jan 21 '16 at 18:34
1
Ah, yes,sed -i
is dumb and will "edit" the file even if nothing changes and report success... Add a-exec grep -q str1 ;
before the existing-exec sed...
That should do. Oh, and next time you reply, make sure you prepend my username with @ so the system notifies me e.g. @don_crissti otherwise I'll never know you replied (I just happened to return here)
â don_crissti
Jan 23 '16 at 2:45
I'm not exactly sure what you're trying to achieve, can you show a list of files, and what output you're expecting to see.
â EightBitTony
Jan 21 '16 at 14:49
I'm not exactly sure what you're trying to achieve, can you show a list of files, and what output you're expecting to see.
â EightBitTony
Jan 21 '16 at 14:49
@EightBitTony I have added examples, please take a look
â KLMM
Jan 21 '16 at 17:05
@EightBitTony I have added examples, please take a look
â KLMM
Jan 21 '16 at 17:05
1
1
You just add
-print
after your -exec
, it will only be executed if the -exec
was successful e.g. find . -type f ( -name *.git -o -name *.txt ) -exec sed -i 'blah_blah' ; -print
. Sure, you'll have to sort the output then.â don_crissti
Jan 21 '16 at 18:11
You just add
-print
after your -exec
, it will only be executed if the -exec
was successful e.g. find . -type f ( -name *.git -o -name *.txt ) -exec sed -i 'blah_blah' ; -print
. Sure, you'll have to sort the output then.â don_crissti
Jan 21 '16 at 18:11
@don_crissti using print giving an error "-print: command not found".
â KLMM
Jan 21 '16 at 18:34
@don_crissti using print giving an error "-print: command not found".
â KLMM
Jan 21 '16 at 18:34
1
1
Ah, yes,
sed -i
is dumb and will "edit" the file even if nothing changes and report success... Add a -exec grep -q str1 ;
before the existing -exec sed...
That should do. Oh, and next time you reply, make sure you prepend my username with @ so the system notifies me e.g. @don_crissti otherwise I'll never know you replied (I just happened to return here)â don_crissti
Jan 23 '16 at 2:45
Ah, yes,
sed -i
is dumb and will "edit" the file even if nothing changes and report success... Add a -exec grep -q str1 ;
before the existing -exec sed...
That should do. Oh, and next time you reply, make sure you prepend my username with @ so the system notifies me e.g. @don_crissti otherwise I'll never know you replied (I just happened to return here)â don_crissti
Jan 23 '16 at 2:45
 |Â
show 3 more comments
3 Answers
3
active
oldest
votes
up vote
0
down vote
It should be easy enough to write a little script that does what you want and exec
the script as an argument to find
. You already have the script and if you replace $filename
by $1
, you have it. Your script will be of the form
#!/bin/bash
sed -i 's/$pattern/$new_pattern/' $1
echo $1 >> changelog
Let us call this script ed_notify
. Now, you can run it on selected files by
cat changelog >> changelog.old
rm changelog
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec ed_notify ;
2
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
Since the filenames for the session are saved inchangelog
, all you have to do issort changelog
to get the file in sorted order at the end of thefind
command.
â unxnut
Jan 21 '16 at 21:11
add a comment |Â
up vote
0
down vote
Your sed
command (with proper quoting):
sed 's/str1/str2/g'
This will change all occurrences of str1
into str2
. A list of files containing str1
can be had from grep -l 'str1'
:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -l 'str1' ;
-exec sed -i 's/str1/str2/g' + >changelist.txt
Here, grep -l
will provide a list of pathnames that will be redirected into changelist.txt
. It will also act like a filter for sed
so that sed
is only run on files that contain the pattern. sed -i
will then make the changes in the files (and remain quiet).
Alternatively, let find
print the pathnames of the files that contain the string:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -q 'str1' ;
-print
-exec sed -i 's/str1/str2/g' + >changelist.txt
Related:
- Understanding the -exec option of `find`
add a comment |Â
up vote
0
down vote
sed -i
rewrites the file (actually makes full new copies of the files) regardless of whether any of the s
commands in the sed
script succeeded or not.
Here, you'd want to avoid running sed -i
on files that don't contain str1
. With GNU tools:
find . -type f ( -name "*.txt" -o -name "*.git" ) -size +3c
-exec grep -lZ str1 + |
while IFS= read -rd '' file; do
sed -i 's/str1/str2/g' "$file" &&
printf '%sn' "$file"
done
That runs one sed
for each of the files that contain str1
and prints the file names if sed
has been successful (for which there has been no error in creating the new version of the file).
Or you can run one grep
and sed
per file:
find . -type f ( -name "*.txt" -o -name "*.git" ) ( -size +3c
-exec grep -q str1 ;
-exec sed -i 's/str1/str2/g' ;
-printf '"%p" was modifiedn'
-o -printf '"%p" was not modifiedn"' )
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It should be easy enough to write a little script that does what you want and exec
the script as an argument to find
. You already have the script and if you replace $filename
by $1
, you have it. Your script will be of the form
#!/bin/bash
sed -i 's/$pattern/$new_pattern/' $1
echo $1 >> changelog
Let us call this script ed_notify
. Now, you can run it on selected files by
cat changelog >> changelog.old
rm changelog
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec ed_notify ;
2
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
Since the filenames for the session are saved inchangelog
, all you have to do issort changelog
to get the file in sorted order at the end of thefind
command.
â unxnut
Jan 21 '16 at 21:11
add a comment |Â
up vote
0
down vote
It should be easy enough to write a little script that does what you want and exec
the script as an argument to find
. You already have the script and if you replace $filename
by $1
, you have it. Your script will be of the form
#!/bin/bash
sed -i 's/$pattern/$new_pattern/' $1
echo $1 >> changelog
Let us call this script ed_notify
. Now, you can run it on selected files by
cat changelog >> changelog.old
rm changelog
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec ed_notify ;
2
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
Since the filenames for the session are saved inchangelog
, all you have to do issort changelog
to get the file in sorted order at the end of thefind
command.
â unxnut
Jan 21 '16 at 21:11
add a comment |Â
up vote
0
down vote
up vote
0
down vote
It should be easy enough to write a little script that does what you want and exec
the script as an argument to find
. You already have the script and if you replace $filename
by $1
, you have it. Your script will be of the form
#!/bin/bash
sed -i 's/$pattern/$new_pattern/' $1
echo $1 >> changelog
Let us call this script ed_notify
. Now, you can run it on selected files by
cat changelog >> changelog.old
rm changelog
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec ed_notify ;
It should be easy enough to write a little script that does what you want and exec
the script as an argument to find
. You already have the script and if you replace $filename
by $1
, you have it. Your script will be of the form
#!/bin/bash
sed -i 's/$pattern/$new_pattern/' $1
echo $1 >> changelog
Let us call this script ed_notify
. Now, you can run it on selected files by
cat changelog >> changelog.old
rm changelog
find . -type f -a ( -name "*.txt" -o -name "*.git") -a -exec ed_notify ;
edited Jan 21 '16 at 18:59
answered Jan 21 '16 at 14:51
unxnut
3,4202918
3,4202918
2
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
Since the filenames for the session are saved inchangelog
, all you have to do issort changelog
to get the file in sorted order at the end of thefind
command.
â unxnut
Jan 21 '16 at 21:11
add a comment |Â
2
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
Since the filenames for the session are saved inchangelog
, all you have to do issort changelog
to get the file in sorted order at the end of thefind
command.
â unxnut
Jan 21 '16 at 21:11
2
2
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
Please edit your answer so that it actually provides an answer. At the moment, this is a comment simply giving a suggestion.
â terdonâ¦
Jan 21 '16 at 15:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut I am unable to understand your answer, I do have a high level idea of what needs to be done. Please provide some code solution, thanks
â KLMM
Jan 21 '16 at 17:06
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
@unxnut Is it possible to achieve this in a single script(will using routines work)? And how do we get sorted order?
â KLMM
Jan 21 '16 at 20:31
Since the filenames for the session are saved in
changelog
, all you have to do is sort changelog
to get the file in sorted order at the end of the find
command.â unxnut
Jan 21 '16 at 21:11
Since the filenames for the session are saved in
changelog
, all you have to do is sort changelog
to get the file in sorted order at the end of the find
command.â unxnut
Jan 21 '16 at 21:11
add a comment |Â
up vote
0
down vote
Your sed
command (with proper quoting):
sed 's/str1/str2/g'
This will change all occurrences of str1
into str2
. A list of files containing str1
can be had from grep -l 'str1'
:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -l 'str1' ;
-exec sed -i 's/str1/str2/g' + >changelist.txt
Here, grep -l
will provide a list of pathnames that will be redirected into changelist.txt
. It will also act like a filter for sed
so that sed
is only run on files that contain the pattern. sed -i
will then make the changes in the files (and remain quiet).
Alternatively, let find
print the pathnames of the files that contain the string:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -q 'str1' ;
-print
-exec sed -i 's/str1/str2/g' + >changelist.txt
Related:
- Understanding the -exec option of `find`
add a comment |Â
up vote
0
down vote
Your sed
command (with proper quoting):
sed 's/str1/str2/g'
This will change all occurrences of str1
into str2
. A list of files containing str1
can be had from grep -l 'str1'
:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -l 'str1' ;
-exec sed -i 's/str1/str2/g' + >changelist.txt
Here, grep -l
will provide a list of pathnames that will be redirected into changelist.txt
. It will also act like a filter for sed
so that sed
is only run on files that contain the pattern. sed -i
will then make the changes in the files (and remain quiet).
Alternatively, let find
print the pathnames of the files that contain the string:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -q 'str1' ;
-print
-exec sed -i 's/str1/str2/g' + >changelist.txt
Related:
- Understanding the -exec option of `find`
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Your sed
command (with proper quoting):
sed 's/str1/str2/g'
This will change all occurrences of str1
into str2
. A list of files containing str1
can be had from grep -l 'str1'
:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -l 'str1' ;
-exec sed -i 's/str1/str2/g' + >changelist.txt
Here, grep -l
will provide a list of pathnames that will be redirected into changelist.txt
. It will also act like a filter for sed
so that sed
is only run on files that contain the pattern. sed -i
will then make the changes in the files (and remain quiet).
Alternatively, let find
print the pathnames of the files that contain the string:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -q 'str1' ;
-print
-exec sed -i 's/str1/str2/g' + >changelist.txt
Related:
- Understanding the -exec option of `find`
Your sed
command (with proper quoting):
sed 's/str1/str2/g'
This will change all occurrences of str1
into str2
. A list of files containing str1
can be had from grep -l 'str1'
:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -l 'str1' ;
-exec sed -i 's/str1/str2/g' + >changelist.txt
Here, grep -l
will provide a list of pathnames that will be redirected into changelist.txt
. It will also act like a filter for sed
so that sed
is only run on files that contain the pattern. sed -i
will then make the changes in the files (and remain quiet).
Alternatively, let find
print the pathnames of the files that contain the string:
find . -type f ( -name '*.txt' -o -name '*.git )
-exec grep -q 'str1' ;
-print
-exec sed -i 's/str1/str2/g' + >changelist.txt
Related:
- Understanding the -exec option of `find`
edited Sep 5 at 12:08
answered Sep 23 '17 at 14:39
Kusalananda
107k14209331
107k14209331
add a comment |Â
add a comment |Â
up vote
0
down vote
sed -i
rewrites the file (actually makes full new copies of the files) regardless of whether any of the s
commands in the sed
script succeeded or not.
Here, you'd want to avoid running sed -i
on files that don't contain str1
. With GNU tools:
find . -type f ( -name "*.txt" -o -name "*.git" ) -size +3c
-exec grep -lZ str1 + |
while IFS= read -rd '' file; do
sed -i 's/str1/str2/g' "$file" &&
printf '%sn' "$file"
done
That runs one sed
for each of the files that contain str1
and prints the file names if sed
has been successful (for which there has been no error in creating the new version of the file).
Or you can run one grep
and sed
per file:
find . -type f ( -name "*.txt" -o -name "*.git" ) ( -size +3c
-exec grep -q str1 ;
-exec sed -i 's/str1/str2/g' ;
-printf '"%p" was modifiedn'
-o -printf '"%p" was not modifiedn"' )
add a comment |Â
up vote
0
down vote
sed -i
rewrites the file (actually makes full new copies of the files) regardless of whether any of the s
commands in the sed
script succeeded or not.
Here, you'd want to avoid running sed -i
on files that don't contain str1
. With GNU tools:
find . -type f ( -name "*.txt" -o -name "*.git" ) -size +3c
-exec grep -lZ str1 + |
while IFS= read -rd '' file; do
sed -i 's/str1/str2/g' "$file" &&
printf '%sn' "$file"
done
That runs one sed
for each of the files that contain str1
and prints the file names if sed
has been successful (for which there has been no error in creating the new version of the file).
Or you can run one grep
and sed
per file:
find . -type f ( -name "*.txt" -o -name "*.git" ) ( -size +3c
-exec grep -q str1 ;
-exec sed -i 's/str1/str2/g' ;
-printf '"%p" was modifiedn'
-o -printf '"%p" was not modifiedn"' )
add a comment |Â
up vote
0
down vote
up vote
0
down vote
sed -i
rewrites the file (actually makes full new copies of the files) regardless of whether any of the s
commands in the sed
script succeeded or not.
Here, you'd want to avoid running sed -i
on files that don't contain str1
. With GNU tools:
find . -type f ( -name "*.txt" -o -name "*.git" ) -size +3c
-exec grep -lZ str1 + |
while IFS= read -rd '' file; do
sed -i 's/str1/str2/g' "$file" &&
printf '%sn' "$file"
done
That runs one sed
for each of the files that contain str1
and prints the file names if sed
has been successful (for which there has been no error in creating the new version of the file).
Or you can run one grep
and sed
per file:
find . -type f ( -name "*.txt" -o -name "*.git" ) ( -size +3c
-exec grep -q str1 ;
-exec sed -i 's/str1/str2/g' ;
-printf '"%p" was modifiedn'
-o -printf '"%p" was not modifiedn"' )
sed -i
rewrites the file (actually makes full new copies of the files) regardless of whether any of the s
commands in the sed
script succeeded or not.
Here, you'd want to avoid running sed -i
on files that don't contain str1
. With GNU tools:
find . -type f ( -name "*.txt" -o -name "*.git" ) -size +3c
-exec grep -lZ str1 + |
while IFS= read -rd '' file; do
sed -i 's/str1/str2/g' "$file" &&
printf '%sn' "$file"
done
That runs one sed
for each of the files that contain str1
and prints the file names if sed
has been successful (for which there has been no error in creating the new version of the file).
Or you can run one grep
and sed
per file:
find . -type f ( -name "*.txt" -o -name "*.git" ) ( -size +3c
-exec grep -q str1 ;
-exec sed -i 's/str1/str2/g' ;
-printf '"%p" was modifiedn'
-o -printf '"%p" was not modifiedn"' )
answered Sep 5 at 12:11
Stéphane Chazelas
286k53528866
286k53528866
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f256791%2fhow-to-get-filenames-when-using-find-and-sed%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I'm not exactly sure what you're trying to achieve, can you show a list of files, and what output you're expecting to see.
â EightBitTony
Jan 21 '16 at 14:49
@EightBitTony I have added examples, please take a look
â KLMM
Jan 21 '16 at 17:05
1
You just add
-print
after your-exec
, it will only be executed if the-exec
was successful e.g.find . -type f ( -name *.git -o -name *.txt ) -exec sed -i 'blah_blah' ; -print
. Sure, you'll have to sort the output then.â don_crissti
Jan 21 '16 at 18:11
@don_crissti using print giving an error "-print: command not found".
â KLMM
Jan 21 '16 at 18:34
1
Ah, yes,
sed -i
is dumb and will "edit" the file even if nothing changes and report success... Add a-exec grep -q str1 ;
before the existing-exec sed...
That should do. Oh, and next time you reply, make sure you prepend my username with @ so the system notifies me e.g. @don_crissti otherwise I'll never know you replied (I just happened to return here)â don_crissti
Jan 23 '16 at 2:45