免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 8586 | 回复: 19
打印 上一主题 下一主题

每三个文件合并为一个大文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-09-27 20:22 |只看该作者 |正序浏览
在某个目录下有 file01,file02,file03,...,file99 个文件
   现在想按顺序每三个文件合并一个大文件并重新命名
   如
     file01,file02,file03合并位大文件的名称位 :file01-03
        其它以此类推。
     问问大家有什么好的方法?
     我的有点繁琐,

论坛徽章:
0
20 [报告]
发表于 2014-10-14 19:29 |只看该作者
本帖最后由 网速20M 于 2014-10-14 19:31 编辑

转自   http://bbs.chinaunix.net/thread-1790335-1-1.html   awk 'FNR==1&&ARGIND%3==1{if(ARGIND>1){print s>f;s=""};f=sprintf("file%02d-%02d",ARGIND,ARGIND+2)}/^set/{print $0>f}/^plot/{$1=s?""1;s=s?s","$00}END{print s>f}' file[0-9][0-9]
他妹的那个笑脸为:$

论坛徽章:
0
19 [报告]
发表于 2010-09-28 10:14 |只看该作者
回复 9# blackold


    何止发大水啊,还有什么拆迁自 焚啊,建什么铅厂啊,假酒什么的,害的我都不敢回去了

论坛徽章:
0
18 [报告]
发表于 2010-09-28 09:56 |只看该作者
for num in $(seq -w 1 99)
        do
                if [ $(echo $num%3|bc) -ne 0 ]; then
                        str=${str}" file"$num;
                        else str=${str}" file"$num;
                        echo $str|perl -ne '{chomp;$str=$_;$first=substr($str,4,2);$end=substr($str,18,2);print "cat $str >file$first-$end\n";}'
                        str=
                        fi
                        done
这个是打印了命令,然后再用shell执行即可。
perl也可以利用system调用命令,直接执行命令

论坛徽章:
0
17 [报告]
发表于 2010-09-28 09:33 |只看该作者
回复 16# lkk2003rty


    让大家挂念啦~好感动~最近在忙个项目~时间上确实有些紧张。不过CU已经是我生活的一部分了
我会坚持来的~谢谢大家~

论坛徽章:
0
16 [报告]
发表于 2010-09-28 09:26 |只看该作者
回复 15# iori809


    最近怎么不见你了。。。。。

论坛徽章:
0
15 [报告]
发表于 2010-09-28 08:56 |只看该作者

论坛徽章:
0
14 [报告]
发表于 2010-09-27 23:31 |只看该作者
本帖最后由 sunbw001 于 2010-09-27 23:39 编辑

回复 13# addictlinux
  1. [root@localhost ~]# name1="abcd"
  2. [root@localhost ~]# j=1
  3. [root@localhost ~]# eval echo \$name$j
  4. abcd
  5. [root@localhost ~]#
  6. [root@localhost ~]# name1="abcd"
  7. [root@localhost ~]# j=1
  8. [root@localhost ~]# eval str=\$name$j
  9. [root@localhost ~]# echo $str
  10. abcd
  11. [root@localhost ~]#
复制代码

论坛徽章:
0
13 [报告]
发表于 2010-09-27 23:14 |只看该作者
本帖最后由 addictlinux 于 2010-09-27 23:15 编辑
  1. #!/bin/sh
  2.   SAVEIFS=$IFS;
  3.   IFS=$'\n'
  4.   rm -fr *-*.gnuplot;
  5.   
  6.   ls *.gnuplot |grep -v "-" | paste -d " " - - - - > tempfile

  7.   for I in `cat tempfile`
  8.        do
  9.           flag=0;
  10.          #j=1;
  11.           name1=`echo "$I" | cut -d " " -f1`;num1=${name1//[a-z_.]}; #newn1=${name1%.*};
  12.           name2=`echo "$I" | cut -d " " -f2`; #newn2=${name2%.*}
  13.           name3=`echo "$I" | cut -d " " -f3`; #newn3=${name3%.*}
  14.           name4=`echo "$I" | cut -d " " -f4`; #num4=${name4//[a-z_.]};newn4=${name4%.*};

  15.            name=("$name1" "$name2" "$name3" "$name4");

  16.            for n in `seq 1 4`
  17.                do
  18.                    if [ ! -z ${name[n]} ]; then
  19.                       let "++flag";
  20.                    fi
  21.                 done

  22. #        echo $flag;
  23.           namestr=${name[flag]//[a-z_.]};

  24.           for m in $name1 $name2 $name3 $name4
  25.                do
  26.                    cat $m>>diff_$num1-$namestr.gnuplot
  27.                done

  28.                 echo -n "plot" >>diff_$num1-$namestr.gnuplot

  29.                  let "num=$flag-1" ;

  30.                for p in `seq 0  $num`
  31.                    do
  32.                     echo -n " \"${name[p]%.*}.file\" with linespoints," >>diff_$num1-$namestr.gnuplot
  33.                    done

  34.                echo "\"${name[flag]%.*}.file\" with linespoints">>diff_$num1-$namestr.gnuplot;
  35.        done

  36.   IFS=$SAVEIFS;
复制代码
衍生问题:name1="abcd"
                j=1;
                ${name$j} 对么? 如何得到name1的结果。// 上文中绕了一大圈就是为了避免此问题。

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
12 [报告]
发表于 2010-09-27 21:41 |只看该作者
回复 11# sunbw001
不是笑话你啊,
你的命令不错啊。
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP