Small batch conversions from Dos Files to Unix files

Source: Internet
Author: User
Tags ultraedit
Article Title: small batch conversion from Dos Files to Unix files. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

For developers who often develop software in both Unix and Windows, file format conversion is required because the Unix operating system line breaks are characters \ n, in Windows, the line break is \ r \ n. Therefore, the format conversion is required when files are transmitted in these two operating systems. In Unix, the file format conversion tool has the dos2unix command, in Windows, UltraEdit can be used for conversion, but we usually use them to convert a single file. To perform batch conversion, you need to write a shell script on your own in Unix, batch replacement is required in Windows. The specific method is as follows: 1. replace multiple Dos Files with Unix files in a Unix environment

#! /Bin/bash

ShowUsage ()

{

Echo "Usage: dos2unixdir [destdir]"

Exit 0

} Dir = $ PWD

If [$ #-gt 1]

Then

ShowUsage

Fiif [$ #-gt 0]

Then

Dir = $1

Either or I in 'Find $ dir'

Do

If [! -D $ I]

Then

Echo "processing file..." $ I

Dos2unix $ I

Fi

Done

Or

Dos2unix is actually to delete ^ M from a text file. I usually don't bother to use this command. In vi, use a command (: % s/^ m/g) to delete it.

Example:

Dos2unix a.txt B .txt

To put a batch of files in dos2unix, you can use the following for statement:

For f in *. txt or for f in *

Do

Dos2unix $ f

Done

Note: * indicates the names of all files in the current directory.

2. in Windows, replace multiple Dos files with Unix files. in UltraEdit, select Search | Search in files. in the Find box, enter ^ p (which indicates the line breaks in DOS files ), in Replace with, enter ^ n, which indicates the line break symbol in UNIX files ). Then, select the file directory for batch replacement and filter the extension.

Http://blog.chinaunix.net/u3/94271/showart_2291548.html

Batch modification from UNIX to DOS

The asc files downloaded from the Siemens bsc may all be in UNIX format. We need to convert them into dos format during processing, which requires a batch conversion process.

First, we need to clarify two questions:

1. The difference between UNIX format and DOS format is that press Enter. In UNIX format, each line's carriage return is represented by a 0x0a character, while in DOS format, each line's carriage return is represented by 0x0d0a. So we only need to replace this one.

2. UltraEdit itself provides the multi-file batch replacement function.

So we can do this:

1. Open UltraEdit

2. Select Replace in the file

3. Enter ^ n in search (the return key character in UNIX format)

4. Enter ^ P in replacement (the carriage return character in DOS format)

5. Select *. asc as the file type.

6. Select the directory of all files to be converted.

7. replace all OK points

This is a big success, isn't it super simple? What batch processing programs do you need to write. The key is to understand the two points I mentioned above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.