A number of times I found the terminal command below, but that only seems to apply to 1 word at the time:
Code: Select all
grep -lr -e '<oldword>' * | xargs sed -i 's/<oldword>/<newword>/g'
Any ideas for a good app? I would prefer that.
Code: Select all
grep -lr -e '<oldword>' * | xargs sed -i 's/<oldword>/<newword>/g'
I use a shell script for that.
Code: Select all
#!/bin/bash
for word in $( cat /path.to/list.of.words ) ; do
rename "s/$word//g" *
done
Code: Select all
able
baker
\ charlie
\ dog
echo
Not exactly... Extract downloaded archive and give execute permission to far.sh to run the app.Klaas Vaak wrote: ⤴Fri Sep 20, 2019 3:58 am I except for Linux you have to download a .tar.xz file and build the app, which is beyond my capabilities and interest.
Code: Select all
find . -type f -iname "*.txt" -exec sed -i "s/oldword1/newword1/g;s/oldword2/newword2/g" {} \;
There are several methods to specify multiple commands in a 'sed' program.
Using newlines is most natural when running a sed script from a file (using the '-f' option).
On the command line, all 'sed' commands may be separated by newlines.
Alternatively, you may specify each command as an argument to an '-e' option:
$ seq 6 | sed '1d
3d
5d'
2
4
6
$ seq 6 | sed -e 1d -e 3d -e 5d
2
4
6
A semicolon (';') may be used to separate most simple commands:
$ seq 6 | sed '1d;3d;5d'
2
4
6
@catweazel: excuse my ignorance, but should that list.of.words be in the same script or is it a separate script that the rename script looks into when it executes its code? I ask because you put it in a different code box.catweazel wrote: ⤴Fri Sep 20, 2019 4:27 am I use a shell script for that.
list.of.words:Code: Select all
#!/bin/bash for word in $( cat /path.to/list.of.words ) ; do rename "s/$word//g" * done
Code: Select all
able baker \ charlie \ dog echo
@ColdBootll: yes, that works. Thanks for pointing it out.ColdBootII wrote: ⤴Fri Sep 20, 2019 7:03 am Not exactly... Extract downloaded archive and give execute permission to far.sh to run the app.
@donalduck: so, if I understand well, one can just add as many old words and new words to that command as one likes.donalduck wrote: ⤴Fri Sep 20, 2019 7:59 am another possible command:
Code: Select all
find . -type f -iname "*.txt" -exec sed -i "s/oldword1/newword1/g;s/oldword2/newword2/g" {} \;
not as many but a lot for sure. there are others limitations !as many old words and new words to that command as one likes
Code: Select all
sed "s/media\/veracrypt1\/Geopolitics\/images\//media\/veracrypt1\/Geopolitics\//g" my-file
Code: Select all
sed "s/\(media\/veracrypt1\/Geopolitics\/\)images\//\1/g" my-file
Example run "rpl" search and replace in all folders (-R) and files in my Documents folder ignoring case in simulation mode.rpl --help
Usage: rpl [options] old_string new_string target_file(s)
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-L, --license show the software license
-x SUFFIX specify file suffix to match
-i, --ignore-case do a case insensitive match
-w, --whole-words whole words (old_string matches on word boundaries only)
-b, --backup make a backup before overwriting files
-q, --quiet quiet mode
-v, --verbose verbose mode
-s, --dry-run simulation mode
-R, --recursive recurse into subdirectories
-e, --escape expand escapes in old_string and new_string
-p, --prompt prompt before modifying each file
-f, --force ignore errors when trying to preserve permissions
-d, --keep-times keep the modification times on modified files
-t, --use-tmpdir use $TMPDIR for storing temporary files
-a, --all do not ignore files and directories starting with .
Code: Select all
rpl -s -i -p -R "PHD21" "phd21" ~/Documents/*.*
user69@neon:~$ rpl -s -i -p -R "PHD21" "phd21" ~/Documents/*.*
Simulating replacement of "PHD21" with "phd21" (ignoring case) (partial words matched)
The files listed below would be modified in a replace operation.
/home/user69/Documents/addressbook_06182017.ldif
/home/user69/Documents/Gmail - Welcome to the SHOUTcast Streaming Service.html
/home/user69/Documents/Ring_ID.txt
/home/user69/Documents/SHOUTcast - Radiomanager.html
A Total of 39 matches found in 89 files searched.
None replaced (simulation mode).
Code: Select all
rpl -i -R "media/veracrypt1/Geopolitics/images/" "media/veracrypt1/Geopolitics/" ~/Documents/test/*.*
Code: Select all
#!/bin/bash
./far.sh
Contrary to popular belief, most Linux Mint users do not have to use or learn the console terminal commands although it can certainly help. There are on occasion some maintenance and or alternate software application installation commands that people can use which can usually be copied and pasted from a post or reply.Klaas Vaak wrote:The reason I enquire about command line possibilities is because in Linux it is a lot more common to use those, plus it could avoid installing yet another app. Then again, when I see some of the syntax involved for F&R it seems to geeky for me. After all, my motto is: I don't want to have to be a mechanic to be able to drive the car.
I like the various file finder apps, but I am surprised they don't offer options for search and replace?Klaas Vaak wrote:I downloaded FAR 4 days ago and have been able to do an F&R exercise with it. I like the GUI. Today, following your earlier mail, I also tried DocFetcher, and even though the possibilities are impressive, it is too "fancy" for my needs, I prefer FAR.
1 last thing you might want to guide me on is a script to run FAR. Is that OK? If not, what do I need to amend? Where should I place the script? Can I place a shortcut/symlink on the desktop to activate it with a click?
Code: Select all
bash /home/user69/apps/far/far.sh
Code: Select all
bash ~/apps/far/far.sh
Code: Select all
./home/user69/apps/far/far.sh
Code: Select all
/home/user69/apps/far/far.sh
You can easily install KDE Kubuntu desktop into Xfce (or Mate) and create what I call Linux Mint "xKDE" (Xfce) or "mKDE" (Mate) which works really well if you want all the cool KDE stuff.Klaas Vaak wrote:P.S.: I like your signature, and checked out the KDE link. I like XFCE, though that might be because of habit.
Code: Select all
java -jar ~/far/far.jar