Regex awk基于第一个字符合并行

Regex awk基于第一个字符合并行,regex,bash,ssh,awk,Regex,Bash,Ssh,Awk,我正在尝试编写一个命令,将文本包文件转换为自动密钥文件。文本文件的格式如下: .abbr This would be the replacement text for the line above in texter. .day Have a GREAt day! .but But some of the information takes up multiple lines .how However all the abbreviations start with a "." and t

我正在尝试编写一个命令,将文本包文件转换为自动密钥文件。文本文件的格式如下:

.abbr
This would be the replacement text for the line above in texter.
.day
Have a GREAt day!
.but
But some of the 
information takes up multiple lines
.how
However all the abbreviations 
start with a "." and 
then x lines of text to be
我需要将每一个文件放在单独的文件中,或将缩写及其替换文本以以下格式打印到相应的字段中:

  "items": [
{
    "usageCount": 0, 
    "omitTrigger": false, 
    "prompt": false, 
    "description": "description", 
    "abbreviation": {
        "ignoreCase": false, 
        "wordChars": "[\\w]", 
        "immediate": false, 
        "abbreviation": "ABBREVIATION GOES HERE", 
        "backspace": true, 
        "triggerInside": false
    }, 
    "hotkey": {
        "hotKey": null, 
        "modifiers": []
    }, 
    "phrase": "REPLACEMENT TEXT GOES HERE", 
    "modes": [
        1
    ], 
    "showInTrayMenu": false, 
    "matchCase": false, 
    "filter": null, 
    "type": "phrase", 
    "sendMode": "kb"
我很确定我可以用awk处理格式化部分,但是我如何才能获取正确的缩写和它的适当替换文本。下面是我为将其打印到单个文件而想到的,我可以将其格式化,但这给了我一个关于close f的错误:

awk '/^\./ {f="$title\."++d} f{print > f} /^\./ {close f; f=""}' 
我写的这个脚本也不起作用:

#!/bin/sh

while read line
do
   if echo $line | grep "^\."; then
       line_no=`echo $line | awk -F "\." '{ print $2 }'
   elif echo $line | grep "^\."; then
       : #ignore
   else
       echo "$line" >> t2ak.$line_no
   fi
done < Default.texter
#/垃圾箱/垃圾箱
读行时
做
如果echo$line | grep“^\”;然后
行_no=`echo$line | awk-F“\”{print$2}
elif echo$行| grep“^\”;然后
:#忽略
其他的
回声“$line”>>t2ak.$line\u编号
fi
done
尝试使用
“\n\”
作为
awk
的recordseparator正则表达式。

这可能适用于您:

csplit -n5 -z file '/^\./' '{*}'

这将把每个缩写放在一个单独的文件中,然后使用sed或awk使用生成的文件填写模板。

我不确定是否理解您的问题。使用上面的示例输入,您是否希望创建4个自动密钥文件?如果我没有正确理解你,你能用一些预期的输出更新你的问题吗?干杯。这非常适合将缩写及其相应的替换文本移动到它们自己的文件中。