[已解决][问题]URL排序问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
caike
帖子: 30
注册时间: 2005-12-09 16:22

[已解决][问题]URL排序问题

#1

帖子 caike » 2008-08-25 23:49

请教各位大大, 我用Spider抓回一些url:

代码: 全选

http://www.xxx/forum-45-1.html
http://www.xxx/forum-1-1.html
http://www.xxx/forum-45-2.html
http://www.xxx/forum-45-3.html
http://www.xxx/forum-45-4.html
http://www.xxx/forum-45-5.html
http://www.xxx/forum-45-6.html
http://www.xxx/forum-45-7.html
http://www.xxx/forum-45-8.html
http://www.xxx/forum-45-9.html
http://www.xxx/forum-45-10.html
http://www.xxx/forum-45-85.html
这些url存在一个叫forum.txt的方本文件里, 在这里我请教两个问题:

1. 如何对这些URL进行排序?

其实抓回的这些URL就是一些分页过的url, forum-45-1.html是第一页, 最后一页呢,应该就是forum-45-85.html这个最大的这个. 所以我想排序, 这样最大的就是最后一页.

2. 怎么取到这个最大值,85, 就是从这个forum-45-85.html抠出85.

这样我就可以做一个For循环, 从forum-45-1.html 到 forum-45-85.html, 来遍历这些页面.

谢谢各位的帮忙.
上次由 caike 在 2008-08-27 11:44,总共编辑 1 次。
java程序员 linux菜鸟 C++初学者
http://ke-cai.net
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#2

帖子 solcomo » 2008-08-26 0:42

sort -t- -k3 -n file
echo forum-45-85.html | cut -d- -f3 | cut -d. -f1
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
caike
帖子: 30
注册时间: 2005-12-09 16:22

#3

帖子 caike » 2008-08-26 0:51

太感谢solcomo, 完美的实现了我想要的功能 :D
java程序员 linux菜鸟 C++初学者
http://ke-cai.net
头像
yjcong
帖子: 2470
注册时间: 2006-02-28 3:11

#4

帖子 yjcong » 2008-08-26 0:53

一梦三年,
松风依旧,
萝月何曾老.


灵幽听微, 谁观玉颜?
灼灼春华, 绿叶含丹.
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#5

帖子 solcomo » 2008-08-26 0:58

sort -t- -k2 -k3 -n file
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
头像
yjcong
帖子: 2470
注册时间: 2006-02-28 3:11

#6

帖子 yjcong » 2008-08-26 3:00

一梦三年,
松风依旧,
萝月何曾老.


灵幽听微, 谁观玉颜?
灼灼春华, 绿叶含丹.
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#7

帖子 solcomo » 2008-08-26 9:31

就用那个命令就可以

-t是设置分隔符
-k是选择排序字段
和awk里的-F和cut的-d差不多
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
头像
yjcong
帖子: 2470
注册时间: 2006-02-28 3:11

#8

帖子 yjcong » 2008-08-26 9:44

一梦三年,
松风依旧,
萝月何曾老.


灵幽听微, 谁观玉颜?
灼灼春华, 绿叶含丹.
回复