[英]awk to merge lines based on 1st character
I am trying to write a command to convert a texter bundle file into an autokey file. 我正在尝试编写一个命令,将文本绑定程序文件转换为自动密钥文件。 The texter file is formatted like so:
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
I need to put each one in a separate file or print the abbrevation and its replacement text into the appropriate fields in the following format: 我需要将每个单独的文件放在一个单独的文件中,或将缩写及其替换文本以以下格式打印到相应的字段中:
"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"
I am pretty sure I can handle the formatting part with awk but How could I grab the proper abbrevation and its appropriate replacement text. 我很确定我可以使用awk处理格式部分,但是如何获取正确的缩写及其适当的替换文本。 Heres what I came up with for the printing it to individual files that I could them format but its giving me an error about close f:
这是我想出的将它打印到可以格式化的单个文件中的方法,但是这给我一个关于close f的错误:
awk '/^\./ {f="$title\."++d} f{print > f} /^\./ {close f; f=""}'
This script wont work either that I wrote: 我写的这个脚本不起作用:
#!/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
This might work for you: 这可能对您有用:
csplit -n5 -z file '/^\./' '{*}'
This will place each abbreviation in a separate file, then use sed or awk to fill in a template using the resulting files. 这会将每个缩写放在一个单独的文件中,然后使用sed或awk使用生成的文件填充模板。
Try using "\\n\\."
尝试使用
"\\n\\."
as awk
's recordseparator regex. 作为
awk
的recordseparator正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.