我正在尝试编写一个命令来将文本包文件转换为自动密钥文件。texter 文件的格式如下:
.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 处理格式化部分,但我如何才能获取正确的缩写及其适当的替换文本。这是我想出的将其打印到可以格式化的单个文件的方法,但它给了我关于关闭 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