Friday, May 3, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 501  / 1 Year ago, mon, january 16, 2023, 4:48:36

I have typed out a long command in the BASH but just as I typed the command I see that I have misspelled the command or argument. I want the cursor to go to the argument or command I have misspelled using inplace search instead of hitting arrow keys to go to the particular command or argument.



E.g.



ls *.txt | grep -e 'foo' >> list_of_text_files_containing_foo.txt


and I want to change foo in grep to bar by find and replace foo to bar inside the command without hitting arrow keys. Is there a way to change all occurrences of foo to bar.


More From » command-line

 Answers
2

You probably are interested about bash quick substitution in the last command:



!!:gs/old/new


Example:



$ ls *.txt | grep -e 'foo' >> list_of_text_files_containing_foo.txt
$ !!:gs/foo/bar
ls *.txt | grep -e 'bar' >> list_of_text_files_containing_bar.txt


For more info about bash substitution, read man bash starting from somewhere from the line 3630.


[#26674] Wednesday, January 18, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
onomicsiberated

Total Points: 217
Total Questions: 98
Total Answers: 107

Location: Luxembourg
Member since Sun, May 28, 2023
1 Year ago
onomicsiberated questions
Wed, Mar 22, 23, 20:38, 1 Year ago
Thu, Oct 6, 22, 05:00, 2 Years ago
;