2

我正在从一个基于 YAML 的系统迁移到另一个,将数据从一种管理风格合并到另一种管理风格。

path/to/directory/one/, 文件名是foobar1.yml, foobar2.yml, ... 在path/to/new/directory/two/, 文件名是FooBar1.yml, FooBar3.yml, ...

在原始系统中,path/to/directory/other/有文件名FooBar1.dat, FooBar2.dat. 它们与 中的文件 1:1 匹配path/to/directory/one/,但它们具有正确的大小写以及不同的扩展名和文件内容。

我想使用 bash 读取 中的每个文件path/to/directory/one/,获取我需要导入的行,更改其中一行,并将它们写入正确的相应文件以path/to/new/directory/two/匹配正确的大小写,如果该文件确实创建一个新文件已经不存在了。

具体来说,我正在尝试将 Minecraft 插件的数据从 Essentials 迁移到 AdminCmd 和 WorldPos。

以下是各种文件和格式的示例:http: //pastebin.com/PMtCMXGt

这里的第一个问题,所以如果我太具体或太模糊,请告诉我。

4

2 回答 2

0

就像是:

cd path/to/directory/one/
for f in *.yml
do
    grep 'whatyouwant' $f >> path/to/new/directory/two/$(sed 's/foobar/FooBar/' <<<$f)
done

我们使用bash“这里的字符串”来构建新的文件名

于 2012-08-31T08:49:00.447 回答
0

我写了一些我认为你可以使用的东西的基础。让我知道它是否派上用场或缺少

DIRONE=/path/to/dir/one
DIROTHER=/path/to/dir/other

for f in $DIRONE/*.yml
do
    basename $f
done | sed -e 's/(.+)\.yml/\1/' | while read name; 
    do

            # find a matching .dat file in $DIRTWO
            for f2 in $DIROTHER/*.dat
            do
                    basename $f2
            done | sed -r 's/(.+)\.dat/\1 \L\1/' | while read nameOrig nameLower; 
                    do
                            if [ $nameLower -eq $name ]; then
                                    #nameLower is foobar1.yml in /path/to/dir/one
                                    #nameHigher is FooBar1.dat in /path/to/dir/two
                                    echo "$nameOrig matches $name"
                                    break;
                            fi
                    done
    done 
于 2013-06-21T06:25:09.130 回答