- Ошибка: Some are Mac OS X (UNIX) and some are Windows
- Решение
- Random Stuff
- Monday, April 16, 2012
- Convert Unix, Windows, Mac line endings using OS X command
- How to make git understand Mac (CR) line endings
- 2 Answers 2
- Smudge and clean filters
- This does not help with existing stored files
- Mac os x fix line endings
- Hint Options
Ошибка: Some are Mac OS X (UNIX) and some are Windows
Написать программу на Си под unix (вывод, ip, маски, широковещательного адреса, mac)
Всем привет! Ребята помогите! Нужно написать программу которая выводит ip адрес, маску.
error C4335: Обнаружен файл в формате Mac: преобразуйте исходный файл в формат DOS или UNIX
Есть программа: //24. Удалить из каждой строки слова, длина которых равна к. #include.
Возможно ли установить Windows новее Windows XP с флешки на Mac mini?
Здравствуйте, у меня вот такой вопрос,у меня комп mac mini но чуть больше года назад пришлось.
Установка windows на mac book: загрузочного диска windows 8 не видно
здраствуйте. у меня такая проблема.. есть mac book и на нем установлена windows 7. мне нужно.
Решение
Помощь в написании контрольных, курсовых и дипломных работ здесь.
Не запускается Windows 10 (на iMac с установленными Mac OS и Windows 10)
Доброго времени суток. Есть iMac с установленным на него Windows 10. Как давно не знаю, так как.
Windows 7 + Unix
Всех с наступающим! Возможно ли установить unix в качестве второй ОС, если на машине уже.
Эмуляция ОС Unix в Windows
Если честно, не знал, в какой раздел поместить тему. Поместил сюда. Подскажите, как написать.
Работа в Unix из под Windows
Имеется Windows система. Мне нужно разобраться в unix. Ставить ее не хочу. Посоветуйте где и.
UNIX формат под Windows
Суть: Надо настраивать много роутеров, меняется в конфигурации (файл config1.dat) только пароль(361.
Источник
Random Stuff
Various ramblings of sysadmin, programmer, dancer, coffee snob, food lover and Winnipegger.
Monday, April 16, 2012
Convert Unix, Windows, Mac line endings using OS X command
Today I had to copy some MySQL data from Debian server into test environment on my MacBook. While importing data from tab delimited text files, I noticed warnings that data in the last column of several tables was being truncated. I looked at the tables and noticed MySQL doing some very strange formatting when printing them. It looked almost as if last column was padded with a bunch of white space. I opened import file in TextWrangler and it appeared fine, but when I looked in document options, I saw this:
The good ol’ EOL (end-of-line) character.
Different operating systems use different characters to mark the end of line:
- Unix / Linux / OS X uses LF (line feed, ‘\n‘, 0x0A)
- Macs prior to OS X use CR (carriage return, ‘\r‘, 0x0D)
- Windows / DOS uses CR+LF (carriage return followed by line feed, ‘\r\n‘, 0x0D0A)
I’m guessing the person who sent me those files first transferred them to his Windows machine in ASCII mode, so newline characters got automatically converted during transfer.
Since some of the files were very big, instead of changing line endings in TextWrangler I decided to use command line (shocking, I know).
First I executed
to confirm existence of the dreaded ^M (carriage return) at the end of every line, and then ran
to generate new files without CR characters.
tr (translate character) is a nice little utility that does just that, substitutes one character with another or deletes it (like in my example). It’s available on pretty much any *nix distro so no need to install additional software.
Источник
How to make git understand Mac (CR) line endings
For some reasons one of my files contains old style Mac line endings (after editing on OSX). These are «CR» (carriage return) characters and show up as ^M in git diff .
Git does not understand that they are line ending codes (really how hard can it be?) and interprets the whole file as a single line.
I know that I can convert the files to LF or CRLF endings and then commit them back, however since git automatically converts my Windows (CRLF) line endings to LF, I was hoping that it would take care of CR line endings as well.
Is there a way to make git interpret CR as a line ending?
2 Answers 2
Create a filter driver plus .gitattributes : create a smudge filter that runs tr ‘\n’ ‘\r’ and a clean filter that runs tr ‘\r’ ‘\n’ , and mark the file(s) in question as using this filter. Store the file inside Git using LF-only line endings. (The filter driver is defined in a .git/config or $HOME/.gitconfig file and the names or name-patterns for the files go in .gitattributes .)
As you have seen, Git strongly prefers newline-terminated lines. (It can work with newline-separated lines, where the last line is missing the terminator, but this means that adding a line results in a change to the previous final line, since it now has a newline terminator while the new final line is missing the newline terminator.) This does not matter for the individual snapshots, but does matter for producing useful diffs.
Modern MacOS uses newlines, like everyone else. Only ancient backwards-compatible formats have CR-only line endings. See, e.g., this SuperUser Stack Exchange web site posting.
Git does not have a built in filter for converting to or from such line endings. Git does, however, have a general purpose mechanism for making alterations in work-tree files.
Remember that when Git stores any file in a snapshot, the file is represented by what Git calls a blob object, which is stored internally in a special, compressed (sometimes highly compressed), Git-only form. This form is not useful to anything but Git, so when you get the files in a useful form—via git checkout , for instance—Git expands them into their usual form for your computer. Meanwhile, any time you take a normal file like this and convert it to Git-only form, Git compresses the file down to its Git-only form. That happens whenever you copy a file back into Git’s index using git add .
The index copy of each file exists while you have the work-tree in place, just like the committed copy. The index copy is in the same Git-only format. The key difference here is that the committed copy can’t be changed, but the index copy can be changed. Running git commit takes a snapshot of whatever is in the index right at that point, and makes that the new snapshot for the new commit. Hence the index acts as what will go into the next commit. Using git checkout , you copy some existing commit into the index, and have Git expand it into the work-tree; then using git add , you selectively replace particular index copies with compressed versions of the work-tree files that you have changed.
This copying, to or from index and work-tree, is the ideal point at which to do Windows-style LF-to-CRLF conversions, or vice versa, so this is where Git does it. If you have some other conversion to perform, not directly built in to Git, this is where you tell Git to do it.
Smudge and clean filters
A smudge filter is one that Git applies when converting a file from compressed index copy to work-tree copy. Here, if you’ve chosen to have newline characters replaced with CRLF Windows-style line enders-or-separators, Git has an internal converter that will do that: eol=crlf . A clean filter is one that Git applies when converting a file from uncompressed work-tree copy to compressed index copy; here again, eol=crlf directs Git to do the backwards conversion.
If you want to replace newlines with CR-only, you must invent your own converters. Let’s say you call the overall process convert-cr :
(instead of *.csv eol=crlf ). This line goes into .gitattributes (which is a commit-able file, and you should commit it).
Now you must define the convert-cr filter. This goes in a Git configuration file, and here we find a minor flaw: the configuration file is not commit-able. This is a security issue: Git will run arbitrary commands here, and if I could commit this file and you clone it, you’ll run the commands I specify, without getting a chance to vet them first. So you must put this into your .git/config yourself, or into your global configuration ( git config —global —edit for instance):
Now whenever Git converts from Git-only format, it will translate the newlines to CRs, and whenever Git converts to Git-only format, it will translate the CRs to newlines.
This does not help with existing stored files
Any existing snapshots that you have today that have \r inside them, are stored that way forever. Git will never change any existing stored file! Stored data are precious and inviolate. There is nothing you can do about this. Well, there is almost nothing: you can throw out those commits entirely, making new and improved commits that you use instead. But that’s quite painful: every commit remembers its parent commits, so if you replace an early commit in your repository, you must replace every child, grandchild, and so on, so that they all remember this new sequence of commits. ( git filter-branch does this job.)
Источник
Mac os x fix line endings
If you’re having trouble getting something to work right, and that something is based on a text file (for example, a Perl CGI script or a page of HTML), make sure you don’t have any hidden Mac line breaks (also called line endings) in the file!
If you installed or modified the file using a GUI-based tool, there’s a chance you accidentally inserted Mac line breaks. I know (from personal experience!) that Mac line breaks can make both Perl scripts and static HTML pages non-functional if they show up in the wrong spot. Read the rest to see how to find and remove the line breaks.
How can you tell? Start a terminal and open the file with the vi text editor. It’s important to use vi, as the other editors will hide control keys from sight.
If you see a bunch of ^M‘s in the file, you have Mac line breaks. There are some shell commands [editor’s note — see the comments for a one-line perl command to fix your files!] that can auto-replace them, but I just used a Mac text editor (either jedit, BBedit, or Alpha) and re-saved the file, making sure to specify UNIX as the file type.
This problem can be very difficult to diagnose, especially if you normally edit in Emacs, and try just cat‘ing the file at the command line. In both cases, you will not see the ^M‘s, and won’t understand why your file isn’t doing what it should!
- Currently 2.43 / 5
You rated: 5 / 5 (7 votes cast)
Hint Options
There are many places where PERL is incredibly handy. This is one of them. You can use
PERL on the command line to change the line ending ( a ‘\r’ (Mac) to a ‘\n’ (UNIX) ):
I have put an alias in my .bashrc file that looks like this:
alias fle=»perl -pi -e ‘s/\r/\n/g’ «
Now I just type fle and everything works file. I use «fle» for «fix line endings,» but
yo can use anything you want to.
Perl is one thing that I would definitely like to learn more about. Thanks for showing me the
easier method!
how did u add the shortcut to .bashrc ?
and where and how can i do this ?
where is .bashrc
If you didn’t install the BASH shell, then you won’t have a .bashrc.
If you are using the default shell for the terminal (tcsh I think), then you should have a .tcshrc file in /Users/username/ directory. To check, open the terminal and type ls -al and hit return. If it is there you can edit it using by typing pico .tcshrc. If it is not there, pico .tcshrc will create it.
Enter you’re aliases in the format
alias name «command in quotes» for example
alias dante «telnet dante.u.washington.edu»
so when you type dante at the terminal, it will open a telnet session to dante.u.washington.edu.
You have to quit the terminal and restart it to see the effects.
if you are using the zsh shell (a lot like BASH I’m told), then the syntax is
alias name=’command’
Using this can result in there being blank lines between each and every line that was there before.
To prevent this use
alias fle=»perl -pi -e ‘s/\r\n?/\n/g’ «
The difference here is the n? which tells to to also replace existing n that is there as long as it is attached to a r.
I hope this helps people
I found that I needed to do like 100 at a time and it wasn’t going to cut it to pass one file at a time. This is what I did:
1. if you don’t have a bin directory in your home directory make one go to the terminal and tyep «mkdir bin»
2. the in the bin directory create a file called ‘fle’ with your favorite editor and then put in this one line:
for T in `ls -a $*`; do perl -pi -e ‘s/rn?/n/g’ $T; done
I chose «T» for no particular reason.
3. Save he file and in the terminal type: chmod 755 fle while in the bin directory.
4. If you want to use it right away, you need to first close whatever terminal window you’re using and open a new one. For some reason when creating new shell scripts this has to be done before you can execute them.
That’s it. Now when you want to do a whole directory you can do:
fle * (or simply fle by itself)
or specify file-names: fle *.php or fle myfile.txt
it will work with one or mulitple files.
You don’t have to close your terminal. Just type «rehash». Note also that the path to your bin directory has to be in your PATH for this to work.
A somewhat more helpful (for me) version of this script reads like this:
The -li is unnecessary and the files I happen to want to deal with are of the TXT sort. However, * would cover everything as well.
The important change, though, is the quotes around $filename (or $T in the above example) so that file names with spaces in them are handled correctly by perl.
Actually, even easier command, using find:
find . -type f -name «DEMO*» -exec perl -pi -e ‘s/\r/\n/g’ \ <\>\;
this changes all files starting with «DEMO». Obviously, you can change that to «*» or whatever suits your needs.
Thought you might like to know how that Perl works:
OK let’s break that down:
perl — pretty obvious, runs the Perl interpreter
-p — says to perl, ‘for every line in the file, do this. ‘
-i — says to perl, ‘send output back to the same file you read from’
-e — says ‘run the next bit as if it’s a script’
s/\r/\n/g : This is the bit that does the work
s// — the substitute command, The ‘/’ are just separators
\r — a ‘return’
\n — a ‘newline
g — means ‘global’, ie for every ocurrance.
So, put that together, and it means ‘substitute every r with n’
(PS — I couldn’t get the backslashes to display in this message !)
Yea, it’s a bit of a problem due to a bug in the way that Geeklog handles them at present.
The only way to make sure they show up (along with frontslashes, brackets, quotes, etc) if
you post in HTML is to encode them:
I edited your post in the database to insert the characters so it reads correctly. This bug will
hopefully be addressed in the next release.
You can also use vi to replace the Mac line breaks using the following command:
NOTE: You will need to type shift+: to get to the colon prompt
in vi you can then enter the command starting with the % symbol.
The ^M actually maps to control+shift+v followed by control+shift+m
(+’s are not included), so in actuality the command looks like this:
:%s/control V control M/control V control M/g
Many thanks to my former Perl teacher for this one—
I used it a whole lot of times in my Perl class. 8^)
To Enter the ‘^M’ character: type Cntrl-V then Cntrl-M. HTH -Excalibur
Use the following shell command:
This will remove the carriage returns (^M) and leave only the unix linefeeds.
This will replace the carriage returns (^M) with unix linefeeds.
—
David Sewell
White Hall, Virginia
Annoyed with seeing ^M end-of-lines when viewing files with less on Mac OS X, I wrote this simple alias:
alias macless ‘tr «\r» «\n»
Install TextWrangler and use twdiff instead. 🙂
There is also the «recode» command line utility, that can be installed with fink. recode can do end-of-line translations, but also charset translations. For example you may want to do recode mac/CR..utf-8 to translate a file that has Mac end-of-lines and MacRoman character encoding (typical of MacOS 9) to a file that has unix end-of-line and UTF-8 character encoding (typical of MacOS X).
Источник