Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
39
votes
4
answers
88654
views
Replace text quickly in very large file
I have 25GB text file that needs a string replaced on only a few lines. I can use `sed` successfully but it takes a really long time to run. sed -i 's|old text|new text|g' gigantic_file.sql Is there a quicker way to do this?
I have 25GB text file that needs a string replaced on only a few lines. I can use
sed
successfully but it takes a really long time to run.
sed -i 's|old text|new text|g' gigantic_file.sql
Is there a quicker way to do this?
eisaacson
(491 rep)
Jan 14, 2016, 07:14 PM
• Last activity: Jul 4, 2025, 08:19 AM
0
votes
1
answers
1953
views
Include spaces and tabs in "awk" search and replace
Another user helped me earlier to fix something I'm doing with awk, where I search for a string at any point in all files and replace two numbers in the same line when I find it. awk -i inplace '/^gene_height/{ $3=sprintf("%.0f",(169+rand()*51));$5=sprintf("%.0f",(169+rand()*51)) }1' * This worked i...
Another user helped me earlier to fix something I'm doing with awk, where I search for a string at any point in all files and replace two numbers in the same line when I find it.
awk -i inplace '/^gene_height/{ $3=sprintf("%.0f",(169+rand()*51));$5=sprintf("%.0f",(169+rand()*51)) }1' *
This worked in the test files that I made (much fewer tags to read), but then in the actual files I'm trying to change for a Crusader Kings mod it's getting blocked because each line in the config file starts with a space then two tabs. I tried removing the "^" before gene_height and that kind of works, but it removes the space and two tabs from the file which might mess up the format and break the mod.
Does anyone know how I can get the above script to read files that start with a space, two tabs, THEN the string "gene_height", and keep the space and two tabs when doing the replacement?
the_pocket_of_big_noob
(11 rep)
Jun 26, 2022, 12:43 AM
• Last activity: Jun 25, 2025, 08:02 AM
2
votes
4
answers
8380
views
How do I remove all \r\n from a file, but preserve \n
I have a CSV with unix line endings, but some of the string values have windows line endings in them: date,notes\n 2014-01-01,"Blah Blah Blah"\n 2014-01-02,"Two things:\r\n - first thing\r\n - second thing\n 2014-01-03,"Foo"\n Note that \n and \r just show where the non-printable characters are in t...
I have a CSV with unix line endings, but some of the string values have windows line endings in them:
date,notes\n
2014-01-01,"Blah Blah Blah"\n
2014-01-02,"Two things:\r\n - first thing\r\n - second thing\n
2014-01-03,"Foo"\n
Note that \n and \r just show where the non-printable characters are in the file, it's not how it would look if you opened it in a text editor.
**I want to remove instances of \r\n, but keep the actual line endings, where it's just \n.** The output should look like:
date,notes\n
2014-01-01,"Blah Blah Blah"\n
2014-01-02,"Two things: - first thing - second thing\n
2014-01-03,"Foo"\n
I need something like
tr -d '\r\n' file.csv
but where it deletes the string \r\n
, rather than either \r
or \n
.
If I try to process it with sed
it's treated like so when processing line-by-line, so it doesn't really work:
date,notes
2014-01-01,"Blah Blah Blah"
2014-01-02,"Two things:\r
- first thing\r
- second thing
2014-01-03,"Foo"
Dean
(551 rep)
Mar 22, 2016, 06:36 PM
• Last activity: Apr 23, 2025, 12:48 PM
3
votes
5
answers
663
views
removing braces statements containing nested braces inside
A typical latex problem: \SomeStyle{\otherstyle{this is the \textit{nested part} some more text...}} Now I want to remove all `\SomeStyle{...}` but not the content. Content contains nested braces. The line above should become: \otherstyle{this is the \textit{nested part} some more text...} Questions...
A typical latex problem:
\SomeStyle{\otherstyle{this is the \textit{nested part} some more text...}}
Now I want to remove all
\SomeStyle{...}
but not the content. Content contains nested braces. The line above should become:
\otherstyle{this is the \textit{nested part} some more text...}
Questions:
1. Does any latex editor offer a way to do it?
2. What editor/script does it?
3. How to do it with sed? [🤓]
My solution is a bash script using sed.
1. prepare text: mark replace string with ascii bell, add newline after each brace
2. loop: find { -> add X to hold space, find } -> remove X from hold space, hold space empty -> remove closing }
3. restore newlines and ascii bell to previous
The script works but fails with:
\badstyle{w}\badstyle{o}\badstyle{r}\badstyle{d}
Iit will become:
wo}rd}
the branching to :f seems not to work.
F=$(sed 's|\\|\\\\|g;s|{|\\{|g' <<< "$1" )
# mark all removestrings with ascii bell and newline
# add newline after each { and }
SEDpre='
s|'"$F"'|\a%\n|g
s|\{|\{\n|g
s|\}|\}\n|g
'
SEDpost='
:a;N;$!ba;
s|\a%\n||g
s|\{\n|\{|g
s|\}\n|\}|g
'
# count the brackets
SED='
/\a%/{
:a
n
:f
/\{/{x;s|$|X|;x;ba}
/\}/{x;
s|X||;
/^$/{x;bb}
x
ba
}
}
b
:b
/\}/{
s|\}||;
N;
s|\n||;
/\a%/bf
}
'
sed -r -E "$SEDpre" "$2" | sed -rE "$SED" | sed -rE "$SEDpost"
Thierry Blanc
(153 rep)
Feb 6, 2025, 10:15 AM
• Last activity: Feb 8, 2025, 07:19 PM
27
votes
10
answers
12848
views
How to replace current word under cursor in Emacs
How do I replace current word under cursor in Emacs? I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. Vi has equivalent command cword and I can use a shortcut to pull the word under cursor for replacement...
How do I replace current word under cursor in Emacs?
I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying.
Vi has equivalent command cword and I can use a shortcut to pull the word under cursor for replacement:
nmap z :%s#\=expand("")\>#
Anybody know how to do it with Emacs?
Think Pl
(483 rep)
Oct 14, 2012, 09:19 PM
• Last activity: Dec 30, 2024, 10:12 PM
0
votes
2
answers
92
views
How to search for a newline that is not preceeded by } and remove it
I want to use `sed` to search for line breaks that are not preceded by `}`. The regex for identifying theses cases is: `[^}]$` . What I want to say: If the line ended without `}` then remove the new line. Any line should end with `}` before the newline. How to put that in `sed` to remove them? **EDI...
I want to use
sed
to search for line breaks that are not preceded by }
.
The regex for identifying theses cases is: [^}]$
. What I want to say: If the line ended without }
then remove the new line. Any line should end with }
before the newline.
How to put that in sed
to remove them?
**EDIT:**
Example:
{'Date': 'Fri, 19 Apr 2019 07:23:14 GMT', 'Server': 'Apache', 'Vary': 'Qualys-Scan', 'Strict-Transport-Security': 'max-age=31536000;includeSubDomains;preload', 'Set-Cookie': 'ASP.NET_SessionId=ivoa5bhet0s2ygkylmimvkie; path=/; secure; HttpOnly;SameSite=strict, SC_ANALYTICS_GLOBAL_COOKIE=12f133ea; expires=Thu, 19-Apr-2029 07:23:14 GMT; path=/; secure; HttpOnly;SameSite=strict, SC_ANALYTICS_SESSION_COOKIE=336B5|1|ivoa5; path=/; secure; HttpOnly;SameSite=strict, incap_ses_885_270026=cDp/VlO1AHgshF9F6SZID==; path=/; Domain=.zurich.co.uk, ___utmvm=dlNaoEsuXSO; path=/; Max-Age=900, ___utmvay=nWJx01KvGT; path=/; Max-Age=900, ___utm=JZy
XEtOwalQ: PtR; path=/; Max-Age=900', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'private', 'Content-Type': 'text/html; charset=utf-8', 'Keep-Alive': 'timeout=5, max=10', 'Connection': 'Keep-Alive', 'X-Iinfo': '8-3925806-3807 NNNN CT(73 151 0) RT(155583 5) q(0 0 3 0) r(6 6) U5', 'X-CDN': 'Incapsula', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked'}
When I applied your script, it combined the lines. However, the new line starts with tab
. How to also remove the spaces if the newline starts with spaces?
None
(219 rep)
May 11, 2019, 12:51 PM
• Last activity: Dec 29, 2024, 09:45 AM
3
votes
5
answers
5590
views
Replace text between brackets
I'm using `awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }'` to replace text in data like: SOMETHING [BAR, WIBBLE] SOMETHING [BAR] This gives the desired result of: SOMETHING [FOO, FOO] SOMETHING [FOO] But now I've had to update the text that requires replacing to be something like: awk '{ gsub(/BAR|WIBBL...
I'm using
awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }'
to replace text in data like:
SOMETHING [BAR, WIBBLE]
SOMETHING [BAR]
This gives the desired result of:
SOMETHING [FOO, FOO]
SOMETHING [FOO]
But now I've had to update the text that requires replacing to be something like:
awk '{ gsub(/BAR|WIBBLE|ME/, "FOO"); print }'
Which turns text like:
SOMETHING [ME, WIBBLE]
into:
SOFOOTHING [FOO, FOO]
How can I limit my replacement to just the text between the brackets (i.e. leave the SOMETHING
alone)?
**EDIT**
I also need robustness across whatever text SOMETHING
might be (e.g. SHE GAVE ME THAT
shouldn't have ME
replaced).
Chris
(279 rep)
Oct 24, 2012, 04:10 PM
• Last activity: Nov 3, 2024, 02:42 PM
44
votes
12
answers
92549
views
How can I "cat" a file and remove commented lines?
I'd like to know if there is a way that I could `cat` file like `php.ini` and remove all lines starting with `;` For example, if the file contained this: ; - Show all errors, except for notices ; ;error_reporting = E_ALL & ~E_NOTICE ; ; - Show only errors ; ;error_reporting = E_COMPILE_ERROR|E_ERROR...
I'd like to know if there is a way that I could
cat
file like php.ini
and remove all lines starting with ;
For example, if the file contained this:
; - Show all errors, except for notices
;
;error_reporting = E_ALL & ~E_NOTICE
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors except for notices
;
error_reporting = E_ALL & ~E_NOTICE
and I ran the correct command cat | {remove comments command}
, then I would end up with:
error_reporting = E_ALL & ~E_NOTICE
**Note** - I assumed that cat
would be the best way to do this but I'm actually fine with the answer using another utility like awk
, sed
, egrep
, etc.
cwd
(46887 rep)
Dec 7, 2011, 05:21 AM
• Last activity: Sep 24, 2024, 01:48 PM
4
votes
4
answers
2308
views
Stuck With Using find and sed to Replace String in Filenames
Following [this post][1] as a reference, I'm able to run a ```find``` and ```sed``` command without it throwing an error, but the filenames remain unchanged. Trying to strip **pronunciation_de_** from all mp3s in the current directory: pronunciation_de_wählen.mp3 pronunciation_de_wange.mp3 pron...
Following this post as a reference, I'm able to run a
It returns all the mp3s in the current directory. Continuing on now that we know this part works...
For
What is meaning of {} + in find's -exec command? I really wanted to take my time and experiment and research before posting this almost-certainly-duplicate question but I'm completely stuck!
and
command without it throwing an error, but the filenames remain unchanged.
Trying to strip **pronunciation_de_** from all mp3s in the current directory:
pronunciation_de_wählen.mp3
pronunciation_de_wange.mp3
pronunciation_de_weil.mp3
pronunciation_de_werden.mp3
pronunciation_de_zentrum.mp3
Before troubleshooting the command, here's a quick sanity check:
. -name "*.mp3"
It returns all the mp3s in the current directory. Continuing on now that we know this part works...
--version
returns **sed (GNU sed) 4.4**
I run . -name "*.mp3" -exec sed -i 's/pronunciation_de_//g' {} \;
To make sure I'm fully understanding what's happening:
.
runs the **find** command in the current directory.-name "*.mp3"
returns any .mp3 filetypes.-exec
executes the next command you type.-i
The **-i** switch means work on the actual files, not a (temporary) copy.For
's/old_word/new_word/g'
:
- The **s** sets sed to substitute mode.
- **/old_word** is the word you want to replace.
- **/new_word** is the word you want to replace with. In my example it'll be blank.
- **/g** apply the replacement to all matches (not just the first).{}
this string will be replaced by the filename during every iteration.\;
the semicolon terminates the **find** command. The backslash escapes the semicolon character in case the shell tries to interpret it literally.
Most of this information I'm getting from random blogs and Stack Exchange posts:
Understanding the -exec option of find
What is meaning of {} + in find's -exec command? I really wanted to take my time and experiment and research before posting this almost-certainly-duplicate question but I'm completely stuck!
NomadicGoose
(41 rep)
Jul 19, 2019, 05:40 AM
• Last activity: Apr 7, 2024, 08:08 AM
1
votes
3
answers
132
views
sed to replace in a file, with both old and new strings in files
I want to automatically comment out a code block in PHP file, as below: The original block: ``` // Enable all errors ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(E_ALL); ``` The new block with comments: ``` /* For the production version, the following codelines...
I want to automatically comment out a code block in PHP file, as below:
The original block:
// Enable all errors
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL);
The new block with comments:
/* For the production version, the following codelines are commented
out
// Enable all errors
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL);
*/
So I plan to put these lines in two files and use sed to perform the replacement automatically. However, after searching online, I only find https://unix.stackexchange.com/questions/20322/replace-string-with-contents-of-a-file-using-sed?rq=1 and https://unix.stackexchange.com/questions/141387/sed-replace-string-with-file-contents , which means either only the source or destination pattern is in one file, and the remaining is in online. But no sample for both in files.
So, how to perform the replacement? Should I use sed or awk?
alancc
(213 rep)
Mar 17, 2024, 04:30 AM
• Last activity: Mar 19, 2024, 12:27 PM
6
votes
3
answers
494
views
zmv: Replace double-quote (") in filename
Using zmv on macOS, I'd like to replace double-quotes (") in filenames with underscores (_). However, I'm having trouble getting the zshexpn to correctly isolate the ". Is there some magical zsh/zmv/zshexpn option I should be using? ``` % zmv -n '(**/)(*)' '$1${(S)2//"/_}' zmv: syntax error in repla...
Using zmv on macOS, I'd like to replace double-quotes (") in filenames with underscores (_). However, I'm having trouble getting the zshexpn to correctly isolate the ". Is there some magical zsh/zmv/zshexpn option I should be using?
% zmv -n '(**/)(*)' '$1${(S)2//"/_}'
zmv: syntax error in replacement
% zmv -n '(**/)(*)' '$1${(S)2//\"/_}'
zmv: syntax error in replacement`
% zmv -n '(**/)(*)' '$1${(Sp)2//\"/_}'
zmv: syntax error in replacement
(This is part of a much larger replace-illegal-characters engagement. I'm hoping to use one zmv expression to do the whole thing.)
Thanks for any assistance.
atlauren
(61 rep)
Jan 17, 2024, 01:20 AM
• Last activity: Jan 17, 2024, 09:04 PM
0
votes
0
answers
172
views
Find and replace in CudaText editor
So I have dump from U-boot and I need to replace specific string in CudaText editor. Here is mine text e101b1e0: 30ef27d8 e792f415 9beea618 5c601de4 .'.0..........`\ e101b1f0: aeaf9d25 e1dd63e9 536b005b 262a5ef4 %....c..[.kS.^*& hilinux # hilinux # md 0xe100f800 0x3E00 e100f800: 1422b556 4b603659 2f...
So I have dump from U-boot and I need to replace specific string in CudaText editor.
Here is mine text
e101b1e0: 30ef27d8 e792f415 9beea618 5c601de4 .'.0..........`\
e101b1f0: aeaf9d25 e1dd63e9 536b005b 262a5ef4 %....c..[.kS.^*&
hilinux #
hilinux # md 0xe100f800 0x3E00
e100f800: 1422b556 4b603659 2ff6c4a4 5e24be15 V.".Y6`K.../..$^
e100f810: bdc025e2 c03d8966 d7120919 dc559b01 .%..f.=.......U.
e100f820: 26f87c02 7d80db89 5c0d3e2a 37712c9d .|.&...}*>.\.,q7
e10173e0: 2be2a0fa 326d07a9 18cb4b7a 4db0a5ef ...+..m2zK.....M
e10173f0: ddd7bcec 1fac59f7 17ca6be6 163ee297 .....Y...k....>.
hilinux #
hilinux # md 0xe100ba00 0x3E00
e100ba00: 33ffc17d 6cda1ed0 a38cfd95 68ffd26d }..3...l....m..h
e100ba10: 98f71c20 54bf4927 bde58fa8 5782df84 ...'I.T.......W
e100ba20: 789b7a0f feadd17f 07135d9e 48d2fef0 .z.x.....].....H
I need delete text bellow
hilinux #
hilinux # md 0xe100f800 0x3E00
(new line is here)
the hex number after md is increasing but it is in format 0x00000000.
The expected text should look like this
e101b1e0: 30ef27d8 e792f415 9beea618 5c601de4 .'.0..........`\
e101b1f0: aeaf9d25 e1dd63e9 536b005b 262a5ef4 %....c..[.kS.^*&
e100f800: 1422b556 4b603659 2ff6c4a4 5e24be15 V.".Y6`K.../..$^
e100f810: bdc025e2 c03d8966 d7120919 dc559b01 .%..f.=.......U.
e100f820: 26f87c02 7d80db89 5c0d3e2a 37712c9d .|.&...}*>.\.,q7
e10173e0: 2be2a0fa 326d07a9 18cb4b7a 4db0a5ef ...+..m2zK.....M
e10173f0: ddd7bcec 1fac59f7 17ca6be6 163ee297 .....Y...k....>.
e100ba00: 33ffc17d 6cda1ed0 a38cfd95 68ffd26d }..3...l....m..h
e100ba10: 98f71c20 54bf4927 bde58fa8 5782df84 ...'I.T.......W
e100ba20: 789b7a0f feadd17f 07135d9e 48d2fef0 .z.x.....].....H
Slobodan Vidovic
(185 rep)
Jan 1, 2024, 04:06 PM
• Last activity: Jan 1, 2024, 04:25 PM
1
votes
1
answers
49
views
Search and replace content
``` PIN A 1 1:3 0:8 0 0:0 PIN B 1 1:0 0 0:0 Z Z:0 PIN C 1 1:3 0:8 0 0:0 Z Z:0 ``` I would like to change the content on PIN A & PIN C only without affecting PIN B to ``` 0 0:3 Z 0:3 ``` Can't seem to find a way to replace without affecting the contents in PIN B using universal search and replace met...
PIN A
1 1:3 0:8
0 0:0
PIN B
1 1:0
0 0:0
Z Z:0
PIN C
1 1:3 0:8
0 0:0
Z Z:0
I would like to change the content on PIN A & PIN C only without affecting PIN B to
0 0:3
Z 0:3
Can't seem to find a way to replace without affecting the contents in PIN B using universal
search and replace method:
perl -i -pe 's/0:0/0:3/g;' text
perl -i -pe 's/Z:0/Z:3/g;' text
Desired Output:
PIN A
1 1:3 0:8
0 0:3
PIN B
1 1:0
0 0:0
Z Z:0
PIN C
1 1:3 0:8
0 0:3
Z Z:3
JSL
(11 rep)
Dec 4, 2023, 06:05 AM
• Last activity: Dec 4, 2023, 07:11 AM
32
votes
5
answers
33521
views
How to report "sed" in-place changes
When using `sed` to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)? For instance, how can I change the command line find . -type f | xargs sed -i 's/abc/def/g' so I can see the changes that are made on the fly?
When using
sed
to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)?
For instance, how can I change the command line
find . -type f | xargs sed -i 's/abc/def/g'
so I can see the changes that are made on the fly?
ricab
(732 rep)
Oct 23, 2013, 05:48 PM
• Last activity: Nov 30, 2023, 07:58 AM
1
votes
2
answers
52
views
replace both filename and filename's content relying solely on pattern found on the name-of-the-file
I'd like to know if it's possible to replace both `filename.ext` and a matched pattern inside its content regarding a pattern founded on the *filename* itself using `sed` (and `grep` also, maybe?). Let me show you as an example a few files that you may re-create with: ``` cat > '[2022] Diary 2022 (e...
I'd like to know if it's possible to replace both
filename.ext
and a matched pattern inside its content regarding a pattern founded on the *filename* itself using sed
(and grep
also, maybe?).
Let me show you as an example a few files that you may re-create with:
cat > ' Diary 2022 (essay, Travels).txt' ' Diary 2022 (list, Recipes).txt' ' Diary 2022 (watchlist, Movies-).txt' ' Diary 2022 (list, Movies+).txt' \(.+\s(\w.+)\)
I'd like things to became like this:
Diary 2022 (essay, Travels).txt
> becomes > travels.txt
and its content becomes >
TITLE/- travels -\TITLE
@
sometext...
Diary 2022 (watchlist, Movies-).txt
> becomes > movies-.txt
and its content becomes >
TITLE/- movies- -\TITLE
@
sometext...
Diary 2022 (list, Movies+).txt
> becomes > movies+.txt
and its content becomes >
TITLE/- movies+ -\TITLE
@
sometext...
```
and so on...
dAllARA
(33 rep)
Sep 7, 2023, 08:59 PM
• Last activity: Nov 17, 2023, 04:24 PM
0
votes
1
answers
114
views
How to do replace with the dte editor
The [dte editor](https://craigbarnes.gitlab.io/dte/#documentation) a small and easy to use console text editor. In readme or its online doc, both says: > * Regex [search](https://craigbarnes.gitlab.io/dte/dterc.html#search) and [replace](https://craigbarnes.gitlab.io/dte/dterc.html#replace) (are the...
The [dte editor](https://craigbarnes.gitlab.io/dte/#documentation) a small and easy to use console text editor.
In readme or its online doc, both says:
> * Regex [search](https://craigbarnes.gitlab.io/dte/dterc.html#search) and [replace](https://craigbarnes.gitlab.io/dte/dterc.html#replace)
(are the key features). However, I haven't found how to do the
replace
anywhere yet.
Even man dte
doesn't mention anything about the replace
operation, or how to get into the command mode to use it.
xpt
(1858 rep)
Oct 29, 2023, 02:38 AM
• Last activity: Oct 29, 2023, 04:17 AM
2
votes
1
answers
192
views
Replacing a character in all files names of a directory
*This is homework!* I'm trying to replace all spaces in file names with an underscore in the `yay` directory. It asks me to use the commands xargs and sh without using $(command). I tried using conducts of commands, but it keeps displaying this message: sh: 1: Bad substitution Could someone explain...
*This is homework!*
I'm trying to replace all spaces in file names with an underscore in the
yay
directory. It asks me to use the commands xargs and sh without using $(command). I tried using conducts of commands, but it keeps displaying this message:
sh: 1: Bad substitution
Could someone explain why this message keeps popping up?
Here's are the commands I tired using:
find yay -type f -print0 | xargs -0 -I {} sh -c 'newname="${1// /_}"; mv "$1" "$newname"' sh
AND
find yay -type f -exec sh -c 'mv "$1" "${1// /_}"' _ {} \;
cow
(81 rep)
Oct 18, 2023, 02:58 PM
• Last activity: Oct 18, 2023, 03:37 PM
0
votes
2
answers
1244
views
Find and Replace Colours in CSS Files from Command Line
I have a load of CSS files in a folder and I want to be able to find and replace different values in all of these files in one go from the command line. So, for example, if I wanted to replace colour #dadce4 with #ececec can this easily be done with a single command? Just to be clear, I'm looking fo...
I have a load of CSS files in a folder and I want to be able to find and replace different values in all of these files in one go from the command line.
So, for example, if I wanted to replace colour #dadce4 with #ececec can this easily be done with a single command?
Just to be clear, I'm looking for something that will make the changes to all files within a directory and any sub directories without having to specify a file name.
caned_monkey
(3 rep)
Nov 26, 2017, 10:52 PM
• Last activity: Oct 18, 2023, 01:19 PM
189
votes
17
answers
112469
views
How can I do a 'change word' in Vim using the current paste buffer?
I have some text in my paste buffer, e.g. I did a `yw` (yank word) and now I have 'foo' in my buffer. I now go to the word 'bar', and I want to replace it with my paste buffer. To replace the text manually I could do `cw` and then type the new word. How can I do a 'change word', but use the contents...
I have some text in my paste buffer, e.g. I did a
yw
(yank word) and now I have 'foo' in my buffer.
I now go to the word 'bar', and I want to replace it with my paste buffer.
To replace the text manually I could do cw
and then type the new word.
How can I do a 'change word', but use the contents of my paste buffer instead of manually typing out the replacement word?
The best option I have right now is to go to the beginning of the word I want to replace and do dw
(delete word), go to the other place, and do the yw
(yank word). Then go back to the replacement area and do p
(paste) which is kind of clumsy, especially if they are not on the same screen.
Michael Durrant
(43563 rep)
Aug 29, 2013, 02:45 PM
• Last activity: Oct 3, 2023, 11:04 AM
1
votes
1
answers
4205
views
How to replace double new line with single using tr?
Given a text, $ cat a.txt Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor vitae. Etiam iaculis ipsum quis lacus convallis finibus. Nunc fermentum, nunc sit amet egestas congue, odio quam sollicitud...
Given a text,
$ cat a.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor
vitae.
Etiam iaculis ipsum quis lacus convallis finibus. Nunc fermentum, nunc sit amet egestas congue, odio quam sollicitudin velit, quis venenatis augue
nibh sed tortor.
I can't remove that double empty lines using this command.
$ tr '\n\n' '\n' < a.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor
vitae.
Etiam iaculis ipsum quis lacus convallis finibus. Nunc fermentum, nunc sit amet egestas congue, odio quam sollicitudin velit, quis venenatis augue
nibh sed tortor.
Replacing single new line with other char works, isn't it strange?
Abdillah
(115 rep)
Jan 5, 2019, 10:44 AM
• Last activity: Sep 29, 2023, 06:21 AM
Showing page 1 of 20 total questions