A short example:
While writing text I mistype an "f" (Screenshot 1) and want to undo it using C-z. The result is a missing rectangle selection and the last line having still an "f" (Screenshot 2).
abcdf abcd
abcdf --> abcd
abcdf abcdf
Instead I would like to keep the rectangle-selection and have no "f" remaining to continue typing.
abcdf abcd
abcdf --> abcd
abcdf abcd
Any suggestions? Thanks in advance!
Related
I have a text file like this:
info
:
I went to Paris
xxx
yyy
zzz
info
:
I went to Italy
aaa
bbb
ccc
I want this text file to be like this
Info : I went to Paris
xxx
yyy
zzz
Info : I went to Italy
aaa
bbb
ccc
So it will be like;
1- finding every colons
2- (a way) double pressing to backspace button and moving to upper line and pressing spacebar + colon + spacebar + delete button which will get those paris and italy lines to the upper line.
Use the regex-based -replace operator:
Tip of the hat to Santiago Squarzon for helping to simplify the regex and substitution.
# Outputs to the screen; pipe to Set-Content to save back to a file as needed.
(Get-Content -Raw file.txt) -replace '(?m)(?<=^info)(?:\r?\n){2}:(?:\r?\n){2}', ' : '
For an explanation of the regex and the ability to experiment with it, see this regex101.com page.
I would like to use pcregrep with its --color option to highlight text that follows a particular pattern:
e.g. if file.txt contains:
bob says hi
chloe says hello
then running:
pcregrep --color '(?:says)(.*)' file.txt
prints
bob says hi
chloe says hello
but what I want is:
bob says hi
chloe says hello
Is there a way to use pcregrep and have it only highlight text that follows a particular regular expression?
The answer appears to be no, you cannot color only part of a match, even if it's non-capturing with (?:..) as in your example.
But if you instead use a positive lookbehind assertion, which anchors the match but is not part of it, you can achieve what you want:
pcregrep --color '(?<=says)(.*)' data
Result:
I have a simple playlist of song files:
1003 James Brown - The Boss Unknown Artist.mp3
1004 James Brown - Slaughters Theme Unknown Artist.mp3
1005 James Brown - Payback(1) Unknown Artist.mp3
...
I would like them in the following format:
1003 James_Brown_-_The_Boss_Unknown_Artist.mp3
1004 James_Brown_-_Slaughters_Theme_Unknown_Artist.mp3
...
Notice that the whitespace behind the number in front is NOT replaced. I have the following simple sed script:
sed "s/ /_/g"
but that replaces also the space after the number. I know how to form capture groups, but that will not help either. How can I convince sed to only apply the replacement to a portion of the input string, rather than the whole string?
You could do
sed 's/ /_/g; s/_/ /'
I.e. first turn all spaces into underscores, then turn the first underscore back into a space.
I need to trim last 8 character of a file name
Example:
Input -Vignesh.dat12345678
expected o/p : Vignesh.dat
I tried using rev but it didn't worked.
Your question says that you need to remove 5 characters, while the description says 8 !!!
Standard Format-
echo Vignesh.dat12345678 | rev | cut -c X- | rev
Assuming you want to remove 8 characters,
echo Vignesh.dat12345678 | rev | cut -c 9- | rev
The above code will remove last 8 characters. To remove n characters, simply put (n+1) instead of X.
I read through the forum for clues how to solve my problem, but none of the related threads are useable for me, with limited programming knowledge, to apply to my specific problem.
My problem is this: I need to get rid of garbage lines that are clustered throughout my file, but are in between clusters of useable lines. I searched the sed manual and other informative sources about deleting ranges that match patterns, but they only mention to delete UNTIL match pattern, not TILL.
Now I would like to specify a range for which sed deletes lines starting from the first line that matches the pattern line till the line that matches the other pattern. Furthermore, sed needs to recognize the patterns that exists at the end of the lines.
For example:
line 1
blah blah 1
blah blah 2
blah blah 3
blah blah 4
line 2
line 3
Result needs to be:
line 1
blah blah 1
line 2
line 3
Please note the multiple lines between line and and line 2. While blah blah 1 needs to stay, the other 3 need to be deleted.
Thanks!
Try this
sed -n '/line 1/{;p;n;p;};/line 2/,$p' sedTest1.txt
#output
line 1
blah blah 1
line 2
line 3
Sed deconstructed :
sed -n '/line 1/{;p;n;p;};/line 2/,$p' sedTest1.txt
| | | | |||-> print the range
| | | | ||-> til end of file (the '$' char)
| | | | |-> range operator (i.e. start,end)
| | | |-> beginning of range to watch for and print
| | |-> now print line, get 'n'ext, print that line
| |-> match the line with text 'line 1'
|-> don't print every line, only ones flagged with 'p'
Read this from the bottom up.
Also, as your data is a sample, AND you refer to it as garbage lines, it may not be this simple.
You'll need to look through sed tutorials to get up to speed.
I hope this helps.
This might work for you:
sed '/line 1/,/line 2/{//!d;/line 1/N}' file
line 1
blah blah 1
line 2
line 3
or this (if the ranges are not consecutive):
sed '/line 1/,/line 2/{//!d;$!N}' file
line 1
blah blah 1
line 2
line 3
$ sed -n '/line 1/{p;n;p;:a;n;/line 2/{:c;p;n;bc};ba};p' input.txt
line 1
blah blah 1
line 2
line 3