Remove file coding mark but preserve its coding
To remove the BOM from the first line of a file you can use something like this sed -e '1 s/^.//' file.txt
.
sed
commands have two parts an address and a command. Most of the time you see sed
used without addresses (which means apply to all lines) but you can restrict the command operation to only specific lines by using addresses.
In this case the address is 1
meaning the first line. So the replacement only applies to the first line and every line is printed (as that is the default sed behaviour).
Mark File For Removal from Python?
import win32file
import win32api
win32file.MoveFileEx("/path/to/lockedfile.ext", None ,
win32file.MOVEFILE_DELAY_UNTIL_REBOOT)
Why does this code keep appearing in my code even if I delete it and save it?
You have the clear
function you declared invoked in some places, and clean
in others.
Depending on what IDE/editor you're using and how you've configured it, if you don't actually have the clean
function declared anywhere, I have a feeling it's auto importing the first clean
function it can find in your directory.
How can I remove the BOM from a UTF-8 file?
A BOM is Unicode codepoint U+FEFF; the UTF-8 encoding consists of the three hex values 0xEF, 0xBB, 0xBF.
With bash, you can create a UTF-8 BOM with the $''
special quoting form, which implements Unicode escapes: $'\uFEFF'
. So with bash, a reliable way of removing a UTF-8 BOM from the beginning of a text file would be:
sed -i $'1s/^\uFEFF//' file.txt
This will leave the file unchanged if it does not start with a UTF-8 BOM, and otherwise remove the BOM.
If you are using some other shell, you might find that "$(printf '\ufeff')"
produces the BOM character (that works with zsh
as well as any shell without a printf
builtin, provided that /usr/bin/printf
is the Gnu version ), but if you want a Posix-compatible version you could use:
sed "$(printf '1s/^\357\273\277//')" file.txt
(The -i
in-place edit flag is also a Gnu extension; this version writes the possibly-modified file to stdout.)
How to mark some code that must be removed before production?
You could also just define stronger task comment markers: FIXME (high priority) and XXX (normal priority) are standard in Eclipse, and you could define more task tags (Eclipse Properties -> Java -> Compiler -> Task Tags)
If you want to fail your build, you could use the Ant (1.7) contains file selector to look for files containing specified text:
<target name="fixmeCheck">
<fail message="Fixmes found">
<condition>
<not>
<resourcecount count="0">
<fileset dir="${pom.build.sourceDirectory}"
includes="**/*.java">
<contains text="FIXME" casesensitive="yes"/>
</fileset>
</resourcecount>
</not>
</condition>
</fail>
</target>
<target name="compile" depends="fixmeCheck">
Obviously, change ${pom.build.sourceDirectory}
to your source directory, and FIXME
to the comment that you want to search for.
Does anyone know a nice way to print out the files found in this fileset in the build file (other than just looking in Eclipse again)?
Remove a file from a Git repository without deleting it from the local filesystem
The git rm
documentation states:
When
--cached
is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.
So, for a single file:
git rm --cached file_to_remove.txt
and for a single directory:
git rm --cached -r directory_to_remove
Commenting code that is removed
Generally, code that is removed should not be commented, precisely because it clutters the codebase (and, why would one comment on something that doesn't exist?).
Your defect tracking system or source control management tools are where such comments belong.
How to remove files from git staging area?
You can unstage files from the index using
git reset HEAD -- path/to/file
Just like git add
, you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository:
git reset HEAD -- .
Also, for future reference, the output of git status
will tell you the commands you need to run to move files from one state to another.
Related Topics
Android Studio 3.0 Emulator Does Not Start
Stty Serial Port Settings for Parity Not Persistent
Can You Attach Amazon Ebs to Multiple Instances
How to Install SQL * Plus Client in Linux
How to Wait for First Command to Finish
How to Use Linux 'Perf' Tool to Generate "Off-Cpu" Profile
How to Determine Ssl Cert Expiration Date from a Pem Encoded Certificate
Splitting Gzipped Logfiles Without Storing the Ungzipped Splits on Disk
Execute Script as Another User Whilst Not Being Root
How to Parse Command Line Options in Bash Shell
Rename Files and Directories (Add Prefix)
How to Convert an Image to Grayscale via the Command Line
Does the Thundering Herd Problem Exist on Linux Anymore
Ldconfig Error:"Is Not a Symbolic Link" When Using Linux Loader