开发者

Combine file names and content

I got several files like this:

First file is named XXX

1
2
3

Second file is named YYY

4
5
6

I would like to write content and the file names to a separate file that would look like this:

1 XXX
2 XXX
3 XXX
4 YYY
5 YYY
6 YYY

Ca开发者_如何学运维n someone suggest a way to do this?


awk '{print $0,FILENAME}' file1 file2

Or Ruby(1.9+)

$ ruby -ne 'puts "#{$_.chomp} #{ARGF.filename}"' file1 file2


Without further explanation of what you actually need this should work:

for file in $(ls)
do
  echo -n $file >> outfile
  cat $file >> outfile
done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜