我问过这个问题一次,但它被关闭,因为它不够清楚。我试图编辑它,但这个网站不允许它。如果下面的信息仍然不够清楚,请不要关闭,并给予我机会来修复它。我有一个.csv文件,其中包含了很多文本。我想要一个bash脚本,将允许我输入一个关键字,然后在zenity文本框中打印与关键字相关的所有列/行。
我的代码,例如:
#!/bin/bash
path="filename.csv"
ans=$(zenity --entry --title="Keyword?" --timeout=10);
function () {
while IFS= read -r i; do echo "${i%?}"; done < "$path"|grep "$ans*"
}
function | zenity --list --title="Results" --text=function --multiple --separator=" " \
--column="tile-of-col1" --column="title-of-col2" --column="title-of-col3" --width 800 --height 200; exit;
我的期望:
title-of-col1 title-of-col2 title-of-col3
keyword info info on same row info on same row
我得到的
title-of-col1 title-of-col2 title-of-col3
keyword,next column,next column keyword,next column,next column
只有第一列包含关键字。我有多个示例,其中关键字出现在整个.csv,但只在第一列
问题是,我怎样才能让文本以列/行格式打印?上面的代码是一个例子。实际的代码没有使用像函数这样的通用术语,但是包含了我不想共享的敏感信息。这不是一个zenity问题。即使我
第一个月
结果仍然是column-with-keyword,next-column-in-row-containing-keyword,next-column-in-row-containing-keyword
基本上,如果我的关键字是help*,那么包含help的任何变体的所有列都将被打印出来,并通过它们的行进行连接
help-me,go to help.com,some more info
help me please,absolutely not,go back to using pen and paper
我想让它看起来像是在一个
help-me go to help.web some more info
help me please absolutely not just use pen and paper
(以上的话都是开玩笑的,无意当真)
1条答案
按热度按时间huus2vyu1#
我不太明白你的问题。
如果您有此CSV
可以使用Miller来grep每个字段中包含
help
的所有记录,并以这种方式创建漂亮的打印输出:输出将为
如果您不希望输出中包含标头,则可以按以下方式更改命令