[英]awk to merge lines based on 1st character
我正在嘗試編寫一個命令,將文本綁定程序文件轉換為自動密鑰文件。 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處理格式部分,但是如何獲取正確的縮寫及其適當的替換文本。 這是我想出的將它打印到可以格式化的單個文件中的方法,但是這給我一個關於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
這可能對您有用:
csplit -n5 -z file '/^\./' '{*}'
這會將每個縮寫放在一個單獨的文件中,然后使用sed或awk使用生成的文件填充模板。
嘗試使用"\\n\\."
作為awk
的recordseparator正則表達式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.