將某個目錄下的文件合並成一行,中間用冒號(:)作為分隔符
1、paste
復制代碼代碼如下:
ls lib | sed 's@^@lib/@g' | paste -s -d ":"
2、 tr
復制代碼代碼如下:
ls lib | sed 's@^@lib/@g' | tr "\n" ":" | sed 's@:$@@'
3、xargs
復制代碼代碼如下:
ls lib | sed 's@^@lib/@g' | xargs | sed 's/ /:/g'
4、awk
復制代碼代碼如下:
ls lib | sed 's@^@lib/@g' | awk "{if(NR%`ls lib | sed 's@^@lib/@g' | wc -l`){ORS=\":\"}else{ORS=\"\n\"};print;}"
5、perl
復制代碼代碼如下:
ls lib | sed 's@^@lib/@g' | perl -pe 's/\n/:/;' | sed 's@:$@@'
6、python
復制代碼代碼如下:
#!/usr/bin/env python
#coding:utf8
import os
def dirList(dir):
filelist = os.listdir(dir)
allfile=[]
for filename in filelist:
allfile.append(dir+'/'+filename)
return allfile
allfile=dirList('lib')
pathjar=':'.join(allfile)
print pathjar