#----------
if [ $# == 0 ]
then
path=`pwd`
else
path=$1
fi
if [ -f $path ]
then
file=${path##*/}
ext=${file##*.}
if [[ "$file" != mac* ]] && [ $ext = "diff" ]
then
new_file="mac_"$file
echo $path "->" $new_file
awk '/^+++|^---|^@@|^diff|^Binary|^File/ { sub(/r$/,"") }; {print}' < $path > $new_file
fi
else
for file in `ls $path`
do
diff2unix $path"/"$file
done
fi
windows下批量混合格式diff转成windows/dos格式diff diff2win.bat
复制代码
::diff2win
::Ruoqian,Chen<piao.polar@gmail.com>
::----------
::Trans file with unix LE(LF) or mix LE(LF/CRLF) to window LE(CRLF)
::----------
::2013.2.16
::usage
::diff2win trans curent dir
::diff2win path trans dir or file
::----------
@echo off
setlocal enabledelayedexpansion
set WorkPath=%cd%
if [%1] neq [] set WorkPath=%1&& (dir /ad %1 >nul 2>nul ) && goto TRANS_DIR || goto TRANS_FILE
:TRANS_DIR
for /f "delims=" %%i in ('dir !WorkPath! /a-d /b ^| findstr .diff$ ^| findstr -v ^win_') do (
echo !WorkPath!/%%i -^> win_%%i
gawk -v BINMODE="rw" "/^+++|^---|^@@|^diff|^Binary|^File/ { sub(/$/,"r") }; {print}" < !WorkPath!/%%i > win_%%i
)
goto :eof
:TRANS_FILE
for /f "delims=" %%i in ('dir %WorkPath% /b') do (
echo %WorkPath% -^> win_%%i
gawk -v BINMODE="rw" "/^+++|^---|^@@|^diff|^Binary|^File/ { sub(/$/,"r") }; {print}" < %WorkPath% > win_%%i
)
::gawk -v BINMODE="rw" "/^+++|^---|^@@|^diff|^Binary|^File/ { sub(/$/,"r") }; {print}" < in > out
::----------
::2013.2.8
::usage
::diff2win < file_in > file_out
::e.g.
::diff2win < unix.diff > win.diff
::----------
::@echo off
::gawk 1
::http://www.easck.com/software/gawk/manual/html_node/PC-Using.html
::Under MS-Windows, OS/2 and MS-DOS, gawk (and many other text programs) silently translate end-of-line "rn" to "n" on input and "n" to "rn" on output.
windonws下直接打各种格式diff winpatch.bat
复制代码










