Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于对URL排序的windows批处理文件脚本_Windows_Batch File_Cmd - Fatal编程技术网

用于对URL排序的windows批处理文件脚本

用于对URL排序的windows批处理文件脚本,windows,batch-file,cmd,Windows,Batch File,Cmd,如何编写windows批处理脚本,通过将具有唯一文件名的URL分组到文本文件中来对URL进行排序?我不知道如何进一步描述我想要实现的目标,但我希望下面的示例能够解释一切: 我想要这个文本 http://example.com/5235/Guava.jpg http://example.com/2725/Guava.jpg http://example.com/4627/Guava.jpg http://example.com/8385/Guava.jpg http://example.com/3

如何编写windows批处理脚本,通过将具有唯一文件名的URL分组到文本文件中来对URL进行排序?我不知道如何进一步描述我想要实现的目标,但我希望下面的示例能够解释一切:

我想要这个文本

http://example.com/5235/Guava.jpg
http://example.com/2725/Guava.jpg
http://example.com/4627/Guava.jpg
http://example.com/8385/Guava.jpg
http://example.com/3886/Lemon.jpg
http://example.com/5896/Lemon.jpg
http://example.com/2788/Lemon.jpg
http://example.com/1758/Lemon.jpg
http://example.com/1788/Apple.jpg
http://example.com/1567/Apple.jpg
http://example.com/8065/Apple.jpg
http://example.com/6467/Apple.jpg
http://example.com/1464/Banana.jpg
http://example.com/6581/Banana.jpg
http://example.com/4642/Banana.jpg
http://example.com/8635/Banana.jpg
http://example.com/2578/Pineapple.jpg
http://example.com/1452/Pineapple.jpg
http://example.com/8652/Pineapple.jpg
http://example.com/9463/Pineapple.jpg
http://example.com/9765/Peach.jpg
http://example.com/3578/Peach.jpg
http://example.com/3583/Peach.jpg
http://example.com/9467/Peach.jpg
http://example.com/3683/Mango.jpg
http://example.com/3479/Mango.jpg
http://example.com/1795/Mango.jpg
http://example.com/7345/Mango.jpg
这样分类

http://example.com/5235/Guava.jpg
http://example.com/3886/Lemon.jpg
http://example.com/1788/Apple.jpg
http://example.com/1464/Banana.jpg
http://example.com/2578/Pineapple.jpg
http://example.com/9765/Peach.jpg
http://example.com/3683/Mango.jpg
http://example.com/2725/Guava.jpg
http://example.com/5896/Lemon.jpg
http://example.com/1567/Apple.jpg
http://example.com/6581/Banana.jpg
http://example.com/1452/Pineapple.jpg
http://example.com/3578/Peach.jpg
http://example.com/3479/Mango.jpg
http://example.com/4627/Guava.jpg
http://example.com/2788/Lemon.jpg
http://example.com/8065/Apple.jpg
http://example.com/4642/Banana.jpg
http://example.com/8652/Pineapple.jpg
http://example.com/3583/Peach.jpg
http://example.com/1795/Mango.jpg
http://example.com/8385/Guava.jpg
http://example.com/1758/Lemon.jpg
http://example.com/6467/Apple.jpg
http://example.com/8635/Banana.jpg
http://example.com/9463/Pineapple.jpg
http://example.com/9467/Peach.jpg
http://example.com/7345/Mango.jpg
换句话说,对于这个特定的例子(每个水果jpeg有四个),我想按照这种方式对行进行排序:1、5、9、13、17、21、25、2、6、10、14、18、22、26等等。我希望你明白我的意思


文本文件始终包含每个“水果”图片数量相同的URL。不能有六个lemon jpg文件和四个guava jpg文件。我希望你明白我的意思。

在你的文件中运行这个。我在上面的评论中描述的算法

#!/bin/bash

FILE=$1
FIRST=$(head -1 $FILE)
COUNT=$(grep $FIRST $FILE | wc -l)
LINES=$(uniq $FILE)
for i in $(seq 1 $COUNT); do
    echo $LINES | tr " " "\n"
done

您可以告诉
sort
从何处开始比较:

/+n                         Specifies the character number, n, to
                            begin each comparison.  /+3 indicates that
                            each comparison should begin at the 3rd
                            character in each line.  Lines with fewer
                            than n characters collate before other lines.
                            By default comparisons start at the first
因此,如果您的URI前缀始终相同(您的注释指出了这一点),那么您可以直接运行该文件

sort /+25 list.txt /O:list_new.txt

它应该按文件名进行排序。

可能是这样的:

@ECHO OFF
SET origfile=urls.txt
SET c=1
SET skip=4
FOR /L %%c IN (1,1,%skip%) DO IF EXIST %origfile%.%%c DEL %origfile%.%%c
FOR /F "tokens=*" %%L IN (%origfile%) DO CALL :process "%%L"
DEL %origfile%
FOR /L %%c IN (1,1,%skip%) DO (
  TYPE %origfile%.%%c >> %origfile%
  DEL %origfile%.%%c
)
GOTO :EOF

:process
ECHO %~1>>%origfile%.%c%
SET /A c=c%%skip+1

其思想是将后续的行输出到不同的文件,每4行重复一次序列(实际上这里4是参数化的,因此您可以轻松地更改它),然后以原始名称连接这些文件。

这是一项编程任务,不是问题。你希望人们为你编写代码吗?我认为一个简单的代码就可以完成这项任务。如果你用一些高级语言,比如Python,它可能是一个简单的代码(尽管我甚至不确定这一点)。这不是一项标准任务。不,这是一项非常简单的任务。但不是一行。这里有一个提示:拿第一行和grep | wc-l看看有多少。你说每个都必须有相同的数量,所以现在我们知道有多少个“单位”。现在
uniq
可以查看唯一的行是什么。将它们回显到一个文件“count”次,其中“count”是以前的wc-l输出。@Drysdam您能写它吗?请,我非常需要它。不幸的是,我正在寻找windows批处理脚本:(做模运算的巧妙方法。哇!正是我所需要的!非常感谢!@Andriy M