Does anyone know how to search something like this in the search box of Notepad++ ?
ID. 213
Debt: 13 $
I want this to be searched like :
"ID. (don'care for the number/any character),newline, Debt(don'care for the number/any character)"
Turn on regular expression mode in Find, with ". matches newline" enabled:
Search for:
ID\.\s.*[\n]+Debt:\s.*$
Older versions of Notepad++ have difficulty matching multi-line regexes, be sure to have version 6+ Notepad++ for this to work.
How about:
ID\..*?Debt:
Don't forget to enable . matches newline
explanation:
(?^:ID\..*?Debt:)
The regular expression:
(?-imsx:ID\..*?Debt:)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
ID 'ID'
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
.*? any character including \n (0 or more times
(matching the least amount possible))
----------------------------------------------------------------------
Debt: 'Debt:'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
Related
Sometimes I need to edit files which should not end with a newline.
However vim\nvim by default do not visualise in any way the newline character at the end of file. Therefore I am not able to:
visually confirm if the file has a newline character at the end or not
remove that character
Are there any setting which would allow me to see the tailing newline character and edit it in the same way as any other characters?
For example, after create 2 files as follows:
echo test > file-with-newline
echo -n test > file-without-newline
opening first one with nvim file-with-newline shows:
test
~
~
file-with-newline
opening second one with nvim file-without-newline shows:
test
~
~
file-without-newline
Navigating with the cursor to the end of line in either case yields the same result (the cursor stops after last visible character: t). There is no way to tell if the newline is there or not, let alone remove it using familiar commands used to remove ordinary characters (or newlines within the file).
You can enable the option :help 'list':
:set list
to show that "newline character" as a $ at the end of the line (among other things):
Note, however, that the option doesn't make the character "editable" in any way.
if the file has a newline character at the end or not
:set eol?
endofline
remove that character
:set noeol nofixeol
:update
hopefully I can make this understandable:
Just say I have this text in a file:
bash-4.2$ 336
1
bash-4.2$ 401
2
bash-4.2$ 403
3
bash-4.2$ 404
4
bash-4.2$ 735
5
bash-4.2$ 894
6
bash-4.2$ 909
7
I want to remove everything on the lines that start "bash", so I am looking for this output:
1
2
3
4
5
6
7
I have been using the regular expression search (with the help of https://regex101.com/r/kT0uE3/1) and if I use this search "bash.*" it removes the line but not the carriage return.
When I change this search to "bash.*\n" it does not find anything (despite regex101 saying it would work).
I think I am missing something obvious and simple but I cannot see the trees for the woods.
Any help is much appreciated.
Ctrl+H
Find what: ^bash-.+\R
Replace with: LEAVE EMPTY
CHECK Match case
CHECK Wrap around
CHECK Regular expression
UNCHECK . matches newline
Replace all
Explanation:
^ # beginning of line
bash- # literally
.+ # 1 or more any character but newline
\R #any kind of linebreak
Screenshot (before):
Screenshot (after):
how do i do this in vi?
awk -F"," awk '{print substr($1,1,10)}'
I only want to keep the first 10 characters of my date column (example 2014-01-01) and not include the timestamp.
I tried to do it in awk but i got this error:
sed: RE error: illegal byte sequence
I believe it is a bash_profile setting error.
This is what i have in my bash_profile:
#export LANG=en_US.UTF-8
#export LOCALE=UTF-8
export LC_CTYPE=C
export LANG=C
in vim, do:
:%norm! 11|D
this will affect all lines in your buffer.
If you like, :s could do this job too.
:%s/.\{,10}\zs.*//
:%s/: apply the substitution to all the lines
.\{,10}: match anything up to 10 times (greedy)
\zs: indicates the beginning of the match
.*: match the rest of the line
/: end of the first part of :s
/: end of the second part of s (since there's nothing between the two /, replace with nothing, ie delete)
For editing blocks of text there is a -- VISUAL BLOCK -- mode accessible via CTRL-V (on Windows ussually CTRL-Q). Then you can press d to delete your selection.
Or with a simple substitute command
:%s/\%>10c.*//
\%>10c - matches after tenth column
. - matches any single character but not an end-of-line
* - matches 0 or more of the preceding atom, as many as possible
Or you can use range
:1,3s/\%>10c.*//
This would substitute for the first three lines.
I'd like to replace all line containining "CreateTime=xxxxx" with "CreateTime=2012-01-04 00:00". May I know how should I do it with vim?
[m18]
Attendees=38230,92242,97553
Duration=2
CreateTime=2012-01-09 22:00
[m20]
Attendees=52000,50521,34025
Duration=2
CreateTime=2012-01-09 00:00
[m22]
Attendees=95892,23689
Duration=2
CreateTime=2012-01-08 17:00
You can use the global substitute operator for this.
:%s/CreateTime=.*$/CreateTime=2012-01-04 00:00/g
You can read the help for the s command from within Vim using:
:help :s
You can read about patterns with :help pattern-overview.
As requested, a bit more about the regular expression match (CreateTime=.*$):
CreateTime= # this part is just a string
. # "." matches any character
* # "*" modifies the "." to mean "0 or more" of any character
$ # "$" means "end of line"
Taken together, it matches CreateTime= followed by any series of characters, consuming the rest of the line.
I have a TeX file that contains lines like
\[ De = 0 \]
Now my boss wants equation numbers so I want them to be like
\begin{equation}De = 0\end{equation}
I tried the following command by escaping the backslash with a backslash.
:%s#\\[#\\begin{equation}#gc
I think this should work but I am getting pattern not found error.
I have looked at
How to include forward slash in vi search & replace
and
http://vim.wikia.com/wiki/Search_and_replace
Can somebody tell what am I doing wrong?
You have to escape both characters: :%s_\\\[ _\\begin{equation}_g.
EDIT: Since you also asked for an explanation:
Why escape the \?
Vim supports different pattern matching styles (see :help /magic), but escape characters have to be escaped in all of them.
Why escape the [?
[] in patterns are used as collections. Thus you have to escape the [ to match it literally.