一次shell中seq的处理
一次shell中seq的处理
www.ahlinux.com

原始脚本
#! /bin/sh
#str1=""
#filecount=`ls -l /root/gjj | wc -l | awk '{print $1}'`
#echo $filecount
for n in `seq $1 $2`
do
filename="/windows_gjj/"${n}".txt"
echo $filename
dos2unix $filename
sed -i '1,76d' $filename
sed -i '41,$d' $filename
sed -i 's/<.*">//g' $filename
sed -i 's/<.*>//g' $filename
sed -i 's/^[[:space:]]*//g' $filename
sed -i '/^$/d' $filename
#sed -i 's/;//g' $filename
#cat $filename >> /tmp/all_gjj.log
flag=`grep " " $filename | wc -l | awk '{print $1}'`
if [ $flag -ne 10 ]; then
cat $filename >> /tmp/all_gjj.log
echo "********************************************************************************************" >> /tmp/all_gjj.log
LCOUNT=`wc -l $filename | awk '{print $1}'`
str1=""
for i in `seq 1 10`
do
sed -i '1d' $filename
str=`head -n 1 $filename`
echo $str >> /tmp.log
str1=${str1}${str}"|"
echo $str1
sed -i '1d' $filename
done
echo $str1 >> /root/gjj.txt
fi
done
脚本中$1,$2 代表起始的序列号。
一开始的时候,用这个脚本来提取文件内容是正常的,但当文件名上7位数的时候,就出现问题了:
如下:
[root@ALL ~]# sh tiqu.sh 2908637 2908640
/windows_gjj/2.90864e+06.txt
dos2unix: converting file /windows_gjj/2.90864e+06.txt to UNIX format ...
dos2unix: problems converting file /windows_gjj/2.90864e+06.txt
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
grep: /windows_gjj/2.90864e+06.txt: 没有那个文件或目录
cat: /windows_gjj/2.90864e+06.txt: 没有那个文件或目录
wc: /windows_gjj/2.90864e+06.txt: 没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
head: 无法打开 “/windows_gjj/2.90864e+06.txt” 读取数据: 没有那个文件或目录
|
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
head: 无法打开 “/windows_gjj/2.90864e+06.txt” 读取数据: 没有那个文件或目录
||
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
sed:无法读取 /windows_gjj/2.90864e+06.txt:没有那个文件或目录
head: 无法打开 “/windows_gjj/2.90864e+06.txt” 读取数据: 没有那个文件或目录
分析:出现这种问题主要是 shell 把7位数字用指数的形式在表示了,从而造成了找不到对应的文件
解决方法:为了能使 7位数仍然以数字的形式出现,试了 seq 中的-f ,-w 之类的选项都没达到预期的效果,最后采用了折中的方法,最高位用字符代替,后6为用seq 生成,用参数-w 保持位数的宽度一致,修该的脚本如下:
#! /bin/sh
#str1=""
#filecount=`ls -l /root/gjj | wc -l | awk '{print $1}'`
#echo $filecount
for n in `seq -w $1 $2`
do
n="2"${n}
filename="/windows_gjj/"${n}".txt"
echo $filename
dos2unix $filename
sed -i '1,76d' $filename
sed -i '41,$d' $filename
sed -i 's/<.*">//g' $filename
sed -i 's/<.*>//g' $filename
sed -i 's/^[[:space:]]*//g' $filename
sed -i '/^$/d' $filename
#sed -i 's/;//g' $filename
#cat $filename >> /tmp/all_gjj.log
flag=`grep " " $filename | wc -l | awk '{print $1}'`
if [ $flag -ne 10 ]; then
cat $filename >> /tmp/all_gjj.log
echo "********************************************************************************************" >> /tmp/all_gjj.log
LCOUNT=`wc -l $filename | awk '{print $1}'`
str1=""
for i in `seq 1 10`
do
sed -i '1d' $filename
str=`head -n 1 $filename`
echo $str >> /tmp.log
str1=${str1}${str}"|"
echo $str1
sed -i '1d' $filename
done
echo $str1 >> /root/gjj.txt
fi
done
[root@ALL ~]# sh tiqu.sh 908636 908640
/windows_gjj/2908636.txt
dos2unix: converting file /windows_gjj/2908636.txt to UNIX format …
|
/windows_gjj/2908637.txt
dos2unix: converting file /windows_gjj/2908637.txt to UNIX format ...
达到预期的目标了!
- 本文来自:Linux学习网
一次shell中seq的处理的更多相关文章
- shell中的set、seq、eval、exec、&&和||
一.set 查看set 帮助: bash -c "help set" 选项: -e:任何命令执行失败(非0 status)直接退出 -x: 打印执行过程的命令行.参数 +e:命令执 ...
- shell中的循环
shell中的循环 for循环 类似于C语言的步长控制 例如: ;i<=;i++)); ); done 将1到10,依次乘以4,然后打印出来. 这里顺便提一下,shell里面表达式的计算,可以有 ...
- shell中for循环总结
关于shell中的for循环用法很多,一直想总结一下,今天网上看到上一篇关于for循环用法的总结,感觉很全面,所以就转过来研究研究,嘿嘿... 1. for((i=1;i<=10;i++));d ...
- shell中的函数、数组、报警系统脚本
1.shell中的函数 函数就是把一段代码整理到了一个小单元中,并给这个小单元起一个名字,当用到这段代码时直接调用这 个小单元的名字即可.格式: function f_name() {commond} ...
- Shell中的数组及其相关操作
http://blog.csdn.net/jerry_1126/article/details/52027539 Shell中数据类型不多,比如说字符串,数字类型,数组.数组是其中比较重要的一种,其重 ...
- shell中的(),{}几种语法用法
转自:https://www.cnblogs.com/HKUI/p/6423918.html 查看脚本语法是否有错误:bash -n modify_suffix.sh跟踪执行sh -x modify_ ...
- shell 中的()【】{}(())
本文转自:https://blog.csdn.net/taiyang1987912/article/details/39551385 shell中各种括号的作用().(()).[].[[]].{} 一 ...
- centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课
centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 ...
- centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件、目录属性 shell数组简单用法 $( ) 和${ } 和$(( )) 与 sh -n sh -x sh -v 第三十五节课
centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件.目录属性 shell数组简单用法 $( ) 和$ ...
随机推荐
- 互联网公司面试必问的mysql题目(上)
又到了招聘的旺季,被要求准备些社招.校招的题库.(如果你是应届生,尤其是东北的某大学,绝对福利哦) 介绍:MySQL是一个关系型数据库管理系统,目前属于 Oracle 旗下产品.虽然单机性能比不上or ...
- P2P技术基础: 关于TCP打洞技术
4 关于TCP打洞技术 建立穿越NAT设备的p2p的 TCP 连接只比UDP复杂一点点,TCP协议的“打洞”从协议层来看是与UDP的“打洞”过程非常相似的.尽管如此,基于TCP协议的打洞至今为止还没有 ...
- inline 关键字
inline 定义一个函数时最好前面再加上static: static inline 定义的函数,会在链接阶段将代码段中没有使用的inline 函数定义“剔除”,从而减小编译体积:即使加了-g参数仍然 ...
- raw_in_fields
在admin后台类中加入raw_id_fields(只适用于外键)后,会显示外键的详细信息
- [转]linux下查看进程内存使用情况
动态查看一个进程的内存使用 1.top命令 top -d 1 -p pid [,pid ...] //设置为delay 1s,默认是delay 3s 如果想根据内存使用量进行排序,可以shift + ...
- 使用nagios插件 check_mysql_health 过程中遇到的error
使用nagios插件 check_mysql_health 过程中遇到的error 1.如果在运行监控mysql插件的时候遇到了error安装以下依赖包就可以解决: yum install perl- ...
- 表空间 -- tablespace
表空间是数据库的逻辑划分,一个表空间只能属于一个数据库.所有的数据库对象都存放在指定的表空间中.但主要存放的是表, 所以称作表空间. Oracle数据库中至少存在一个表空间,即SYSTEM的表空间. ...
- <转>CentOS 7 安装配置 NFS
CentOS 7 安装配置 NFS 环境 nps 192.168.1.97 client 192.168.1.98 一.yum 安装 yum -y install nfs-utils rpcbind ...
- php判断是否为ajax请求
先说前端使用 jQuery 时怎么区分: jQuery 发出 ajax 请求时,会在请求头部添加一个名为 X-Requested-With 的信息,信息内容为:XMLHttpRequest 在后端可以 ...
- 使用模板创建第一个Web API项目
软件环境 vs 2015 update3 本节将通过例子讲述创建Web API 项目的方法 第一步,打开vs ,依次通过[文件]菜单,[新建][项目]命令,大致步骤如下图 : 第2步,在弹出对话框 ...