I have a project in Visual Studio that can build and run successfully. I need to make it work in Linux. One problem is that the newline character is different from that in Linux, thus I'm getting tons of warnings saying that "no newline at end of file". Appending newline characters to all files one after another is tedious, I'm wondering whether there is a Linux command that I can use to perform the same operation (here, the operation is append newline to end of file) to all files in a directory in Linux?
Thanks in advance!
-Leonora
Most linuxes have a dos2unix command that helps with file conversions.
Related
I'm trying to configure OpenSwan, an open source IPsec solution written in C.
I have a script to download a configuration file ipsec.conf on an Amazon Linux EC2 that was created on my Macbook and uploaded to S3.
When I start the ipsec service, it segfaults.
Curiously, if I open the configuration file with VIM, make no changes, and simply write/quit, it works. This lends me to believe somehow the file has some weird characters/formatting.
I know of dos2unix, which I ran on the configuration file but that did not prevent the segfault.
I'm wondering what exactly VIM is doing when I write/quit. I could script that operation on my configuration file after pulling it. Or anything else that would help me understand what's going on.
First, try to open the file with vim, then exit vim (:q) without having saved the file before. If vim says File modified since last complete write; write or use ! to override., this means that this is not something that vim does when write/quit that changes your file, but that this is something that vim does when it opens the file. And this is the most common case.
Vim parses the input file depending on the locale, and if some characters can not be understood according to the locale, vim may forget them. So, when saving the file, those characters will be removed.
Now, use vim to save your file as ipsec-ok.conf.
And run the following command:
bash -c 'diff <(od -xa ipsec.conf) <(od -xa ipsec-ok.conf)'
This will display the differences between the original file and the one that works with OpenSwan. In ascii and hexadecimal formats. This way, you will find the unsupported characters that make OpenSwan dump a core.
I want to delete a file whose name is stored in a variable, but it doesn't work. I'm getting
A file or Directory in the path name does not exist
My code is
value=$(<try_text.txt)
rm -f /home/inform/output/$value
when i tried deleting i got :
cannot remove `/home/oracle/Omar2/B2BFiles/bm.txt\r': No such file or directory
where does the \r come from ?
It comes from an editor which wrote the Windows line ending \r\n to try_text.txt. When reading that file, the Linux shell removed the Unix line ending \n, and the \r remained. To get rid of it, see e. g. the answers to the question Line ending issue DOS > Linux > Java.
Try this:
value=try_text.txt
rm -f /home/inform/output/$value
Don't run the value variable in a subshell when it's not needed.
EDIT
Previously misunderstood the question, didn't see the '<'.
This works on my system:
value=$(</home/user/Documents/try_text.txt)
rm -f /home/user/Documents/$value
as #gile said, make sure the try_text.txt is in your working directory.
I seem to be having an issue.
I'm trying to write a batch file that uses Linux commands such as rm, mv, clear, and cat within a Windows batch file, but the catch is I can't seem to figure out what I need to do in order for the Windows command line to recognize that when I type in mv I want it to move a file for me, or rm to remove a file of course.
So far all I have figured out is that I could possibly use __DOSKEY__ but it doesn't work in batch files or with parameters (doh!). Thus, all I have gotten so far is:
#echo off
mv dummy.txt
Now my question is how do I get the Windows command line to recognize that mv = move ? Everytime I run the file it just gives me a blank command line.
I know this may sound stupid but my experience is more on the Linux side of the command line than the Windows side, and any help would be greatly appreciated!
Internal cmd commands cannot be aliased. For external commands, you could create hardlinks, but "move" for example is an internal command.
I open an XML file in Vim and found that there are a lot of ^M and ^G symbols showen in it.So I try to use dos2unix to drop the ^M symbols,but it told me that the file is binary file, which makes it skipping the file.After drop the ^G symbols manunally, dos2unix is successfully process that file. My question is: what does ^G actually mean here ? Is it ^G in a file makes it a binary file?
^G is the bell character. When the file is displayed on a traditional terminal, you will hear a beep when you reach that character. There is no difference between "binary" and "text" files, really, so dos2unix is just guessing, and in this case guessing wrong. You can use the option -f to force it to convert files it thinks are binary.
To add to the above answer, Ctrl-M is also usually an end-of-line / linebreak character corresponding to the "\r\n" carriage return used by Windows.
You can read more about in the answers to this question, which include some methods of converting them to unix-style line endings (if you need to): What does ^M character mean in Vim?
I'm using a windows PC and editing files checked out from SVN, which has files checked in using DOS.
I use cygwin and when I either create a new file or patch a file using cygwin binaries the file format is unix. Really I need to always use DOS format for these so my colleagues are not inconvenienced.
Is there any way I can have cygwin use DOS format for say a bash session?
I appreciate I can run unix2dos against such files but this is a pain - I'd rather just have them as DOS to begin with if possible.
You can make SVN do this conversion for you automatically. Check out propset and the eol-style option:
http://svnbook.red-bean.com/en/1.1/ch07s02.html#svn-ch-7-sect-2.3.5
This will make the files always have the newline sequence native to the platform on which you checked out the files (i.e., you may get them in LF and the other ones will have the same files with CRLF):
svn propset svn:eol-style native put-your-filenames-here
You can choose the UNIX or DOS file format during the installation of cygwin.