zoukankan      html  css  js  c++  java
  • Linux和Windows下的批处理操作

    1.windows:

    代码如下test.bat

    @echo off
    set "n=-1"&set "flag=a"
    :begin
    set /a n+=1
    if %n% equ 0 (set "m=") else (set "m=skip=%n%")
    for /f "%m% delims=" %%i in (1.txt) do echo %%i&if defined flag goto next
    set no=a
    :next
    for /f "%m% delims=" %%i in (2.txt) do echo %%i&goto begin
    if not defined no set "flag="&goto begin
    pause>nul
    
    @echo off&setlocal enabledelayedexpansion
    set "num=0"
    for %%a in (1.txt 2.txt) do (
    for /f "delims=" %%i in (%%a) do (
    set /a n+=1
    if !n! gtr !num! set "num=!n!"
    set /p=%%i <nul>>temp.txt
    )
    echo.>>temp.txt&set "n=0"
    )
    :lp
    set /a n+=1
    for /f "tokens=%n%" %%i in (temp.txt) do echo %%i
    if %n% neq %num% goto lp
    del /q temp.txt&pause>nul
    

    正常:

    大文件:

    2空:

    都空:

    2.Linux:

    test.sh代码如下:

    #! /bin/bash
    
    function printLine() {
    pri=`cat $1 | head -n$2 | tail -1f`
    #字符串长度是否为0,不为0输出
    if [ -n "${pri}" ]
    then
    echo ${pri} 
    fi
    }
    
    file1=./1.txt
    file2=./2.txt
    
    
    m=`cat ./${file1} | wc -l`
    
    n=`cat ./${file2} | wc -l`
    
    
    
    max=
    min=
    moreTxt=
    if [ ${m} -gt ${n} ]
    then
    max=${m}
    min=${n}
    moreTxt="${file1}"
    else
    max=${m}
    min=${n}
    moreTxt="${file2}"
    fi
    
    
    i=1
    while (( i <= ${min} ))
    do
    printLine ${file1} ${i}
    printLine ${file2} ${i}
    
    let i++
    done
    
    
    while (( i <= ${max} ))
    do
    printLine ${moreTxt} ${i}
    let i++
    done
    

    正常:

    大文件:

    1空:

    都空:

  • 相关阅读:
    使用SuperWebSocket 构建实时 Web 应用
    slam for Windows 库安装及应用libfreenect2
    《SLAM十四讲》g2o_custombundle在windows轻松调通
    windows下命令行查看库依赖
    zend studio控制台中文乱码
    http协议转
    mysql 字段 增删改
    PHP内部函数
    分层设计
    SecureCRT上传和下载
  • 原文地址:https://www.cnblogs.com/journey97/p/14078567.html
Copyright © 2011-2022 走看看