[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
批处理,还是shell。不要混淆!

TOP

把原文件打包上来看看!

TOP

本帖最后由 Gin_Q 于 2020-3-21 13:02 编辑
  1. #!/bin/bash
  2. rm -f result.txt result1.txt 2>/dev/null
  3. for a in `ls *.txt`
  4. do
  5. grep -o -E "\-[0-9]{1,12}.[0-9]{1,12}" $a | awk -v fname=$a '{printf "%s %s\n",fname,$1}' 1>>result1.txt
  6. done
  7. sort -nr -t ' ' -k 2 result1.txt 1>result.txt
  8. rm -f result1.txt
复制代码
  1. cccc.txt -5.65679881107
  2. cccc.txt -23.8882046924
  3. aaaa.txt -56.5589881107
  4. bbbb.txt -268.882046924
  5. aaaa.txt -2603.82046924
  6. bbbb.txt -5655.89881107
复制代码

TOP

还有一个难点我没有明白你的意思!
  1. #!/bin/bash
  2. rm -f result.txt result1.txt 2>/dev/null
  3. for a in `ls *.txt`
  4. do
  5. grep -o -E "[[:space:]]{2}-[0-9]{1,12}.[0-9]{1,12}[[:space:]]{2}" $a | awk -v fname=$a '{printf "%s %s\n",fname,$1}' 1>>result1.txt
  6. done
  7. sort -nr -t ' ' -k 2 result1.txt 1>result.txt
  8. rm -f result1.txt
复制代码
  1. cccc.txt -5.65679881107
  2. dddd.txt -9.63598741107
  3. cccc.txt -23.8882046924
  4. aaaa.txt -56.5589881107
  5. dddd.txt -65.8839646924
  6. bbbb.txt -268.882046924
  7. aaaa.txt -2603.82046924
  8. bbbb.txt -5655.89881107
复制代码

TOP

本帖最后由 Gin_Q 于 2020-3-21 15:12 编辑

我对shell了解不多,你应该多学学linux三剑客
排序文本最后一次匹配到的数据
  1. #!/bin/bash
  2. rm -f result.txt result1.txt 2>/dev/null
  3. for a in `ls *.txt`
  4. do
  5. for b in `grep -o -E "[[:space:]]{2}-[0-9]{1,12}.[0-9]{1,12}[[:space:]]{2}" $a`
  6. do
  7. temp=$b
  8. done
  9. echo $temp |awk -v fname=$a '{printf "%s %s\n",fname,$1}' 1>>result1.txt
  10. done
  11. sort -nr -t ' ' -k 2 result1.txt 1>result.txt
  12. rm -f result1.txt
  13. #grep -o -E "[[:space:]]{2}-[0-9]{1,12}.[0-9]{1,12}[[:space:]]{2}" $a | tac n 1 |awk -v fname=$a '{printf "%s %s\n",fname,$1}' 1>>result1.txt
复制代码
  1. cccc.txt -23.8882046924
  2. dddd.txt -65.8839646924
  3. bbbb.txt -268.882046924
  4. aaaa.txt -2603.82046924
复制代码

TOP

在第四行前面第三行下面
  1. sed.exe -i '4i abcd' aaaa.txt
复制代码

TOP

你的方法可以
给你个查找空行的方法,剩下的自己想办法咯!
  1. grep -n -E "^$" aaaa.txt
复制代码

TOP

返回列表