Linux 命令行合并文件问题

jazzi · January 07, 2015 · Last by jazzi replied at January 10, 2015 · 7705 hits

请教:如何把一个文件中的内容合并到 100 个文件的头部?

即假设有文件 A1,B1...B100,让 A1 中的内容出现到 B1...B100 每个文件的头部

尝试搜寻了几个都不理想,有请各位支招 :thanks:

假设你所有的的文件都在一个目录下,几行代码就能搞定了

insert.sh

#!/bin/env bash

files=`ls |grep -v A1 |grep insert.sh`

for f in $files; do
    cp a.log $f.tmp
    cat $f >> $f.tmp
    mv $f.tmp $f
done

sed -i '1i {the text you want, you can read from file}' file1 file2

Works. Thank you very much.

You need to Sign in before reply, if you don't have an account, please Sign up first.