Add text to the End of each File with Notepad++ and Regex - append

I have 100 files and need to append a line in the end of each single file.
Is there a way how I can do this with Notepad++?

The answer of Lickro is great and works with Notepad++.
Here is a screenshot of the settings:
I am adding a linebreak \n and then the text.

You can search for
(.*)
and replace with
"\1"
with multiline regular expression option activated. In this case (.*) matches whole text in a file and because of the brackets around you can access the match using \1 and append something after that.

suggest you use a batch file
FOR %%G IN (*) DO echo "myline" >> %%G "C:\myDir"
should append myline to all files in myDir

Related

Use sed for Mixed Case Tags

Trying to reformat tags in an xlm file with gnu sed v4.7 on win10 (shoot me). sed is in the path and run from the Command Prompt. Need to escape some windows command-line characters with ^.
sourcefile
BEGIN
...
<trn:description>V7906 03/11 ALFREDOCAMEL HATSWOOD 74564500125</trn:description>
...
END
(There are three spaces at the start of the line.)
Expected output:
BEGIN
...
<trn:description>V7906 03/11 Alfredocamel Hatswood 74564500125</trn:description>
...
END
I want Title Case but this does in-place to lower case:
sed -i 's/^<trn:description^>\(.*\)^<\/trn:description^>$/^<trn:description^>\L\1^<\/trn:description^>/g' sourcefile
This command changes to Title Case:
sed 's/.*/\L^&/; s/\w*/\u^&/g' sourcefile
Can this be brought together as a one-liner to edit the original sourcefile in-place?
I want to use sed because it is available on the system and the code is consistently structured. I'm aware I should use a tool like xmlstarlet as explained:
sed ... code can't distinguish a comment that talks about sessionId tags from a real sessionId tag; can't recognize element encodings; can't deal with unexpected attributes being present on your tag; etc.
Thanks to Whirlpool Forum members for the answer and discussion.
It was too hard to achieve pattern matching "within the tags" in sed and the file was well formed so the required lines were changed:
sed -i.bak '/^<trn:description^>/s/\w\+/\L\u^&/g; s/^&.*;\^|Trn:Description/\L^&/g' filename
Explanation
in-place edit saving original file with .bak extension
select lines containing <trn:description>
for one or more words
replace first character with uppercase and rest with lowercase
select strings starting with & and ending with ; or Trn:Description
restore codes by replacing characters with lowercase
source/target filename
Note: ^ is windows escape character and is not required in other implementations

How to remove part of text after certain sign in bash

I have .txt file which has following data:
user-5
user-10
user-12
user-23(some text)
user-11#dsa.dsd
user-23-sometext
I want to leave only user-NUMBER. So I have to remove text after #, ) and second -.
I'm trying to use sed command, already succed with # and ). How can I remove text after second -?
My code: sed 's/[)|#].*//g'
sed 's|\(user-[0-9]*\).*|\1|'
This way you don't need to include every possible character that would terminate a user-NUMBER match.

Using powershell how to replace pageBreak in a text file?

What I am trying to do is to create a word document from the text file. But the text file has pageBreaks in it. I want to remove or replace those pageBreaks in the text file. This is to allow me to add pageBreaks in the word document that I'll subsequently create in places where I actually need it.
Below is the PowerShell code that I tried myself to replace the pageBreak in the text file. This doesn't work. As using "`f" in place of pageBreak doesn't work.
$oldWord = "`fPage"
$newWord = "Page"
#-- replace the page breaks in the file
(Get-Content $inputFilePath) -replace '$oldWord', '$newWord' | Set-Content $inputFilePath
The symbol shown for pageBreak in the text editor UltraEdit is ♀
Replacing the character in UltraEdit is easy. I want to replace or remove this using Powershell.
Below is a related question. But still unanswered with regards to PowerShell code.
How to remove unknown line break (special character) in text file?
for page breaks , you can use :
[io.file]::ReadAllText( 'H:\oldFile.txt') | %{$_.replace("`f","")} >h:\newFile.txt
below snippet will work from powershell v3:
cat H:\oldFile.txt -raw | %{$_.replace("`f","")} >h:\newFile.txt
Thanks for the question! This one was interesting.
So the Form-Feed special character is a bugger in powershell. If you echo it out, you just get an odd character, or a square if you cannot display it. But if you copy and paste it back into the powershell terminal, if just moved your command entry point to the top of the screen. Odd.
What I did was try to find ways of replacing general special characters. You can use regexes in powershell using $oldWord -replace 'REGEX_GOES_HERE', 'THING_TO_REPLACE_WITH_HERE, so what I came up with is this:
$oldWord -replace '[\f]', '' #You can also use \r for carriage return, \n for new line, \t for tab, \s for ALL whitespace
This will simply remove all instances of the Form-Feed character.
Hope this helps! Cheers!

Replace 3 lines with another line SED Syntax

This is a simple question, I'm not sure if i'm able to do this with sed/awk
How can I make sed search for these 3 lines and replace with a line with a determined string?
<Blarg>
<Bllarg>
<Blllarg>
replace with
<test>
I tried with sed "s/<Blarg>\n<Bllarg>\n<Blllarg>/<test>/g" But it just don't seem to find these lines. Probably something with my break line character (?) \n. Am I missing something?
Because sed usually handles only one line at a time, your pattern will never match. Try this:
sed '1N;$!N;s/<Blarg>\n<Bllarg>\n<Blllarg>/<test>/;P;D' filename
This might work for you:
sed '/<Blarg>/ {N;N;s/<Blarg>\n<Bllarg>\n<Blllarg>/<test>/}' <filename>
It works as follows:
Search the file till <Blarg> is found
Then append the two following lines to the current pattern space using N;N;
Check if the current pattern space matches <Blarg>\n<Bllarg>\n<Blllarg>
If so, then substitute it with <test>
You can use range addresses with regular expressions an the c command, which does exactly what you are asking for:
sed '/<Blarg>/,/<Blllarg>/c<test>' filename

nmake - how to force echo command to output the tab character?

How to force echo command to output a tab character in MS nmake makefile?
Verbatim tabs inserted right into a string after echo command are removed by nmake and don't show up in the output file.
all :
#echo I WANT TO OUTPUT THE <TAB> CHARACTER HERE! > output.txt
You can use a variable with TAB char. Put this lines in your .bat file:
set tab=[stroke TAB char from your keyboard]
echo a%tab%b>yourfile.txt
Doing so, yourfile.txt will have text a[TAB]b
As a workaround, you can create a file containing the tab character, named input.txt (not using nmake), and then say:
all :
#copy /b input.txt output.txt
I assume you already have tried to put the tab inside quotes?
all:
#echo "<TAB>" > output.txt
DOS and Windows have ugly text support in native batch files :).
Here is nice way to do your task:
install Python interpretator
write simple script which appends character with specified code to file
call script wherever you want :)
Simple script:
'''
append_char.py - appends character with specified code to end of file
Usage: append_char.py filename charcode
'''
import os
import sys
filename = sys.argv[1]
assert os.path.exists(filename)
charcode = int(sys.argv[2])
assert 0 <= charcode <= 255
fh = open(filename, 'ab')
fh.seek(0, os.SEEK_END)
fh.write(chr(charcode))
fh.close()
using this script from batch file you can create any possible file in universe :)
output.txt:
<<output.txt
I WANT TO OUTPUT THE <TAB> CHARACTER HERE!
<<KEEP
<TAB> represents a literal tab character here of course.
I had the same need. I used the answer using the quotes around the character and just took it one step further.
{tab} means pressing the keyboard tab key in the text editor.
SET tab="{tab}"
SET tab=%tab:~1,1%
The second line extracts the middle character from the quoted string.
Now you can use the %tab% variable with ECHO and, I suspect, anywhere else it's needed.
ECHO %tab%This text is indented, preceded by a tab.
I suspect this technique could be used with other problem characters as well.