如何在shell脚本/ bash中将.txt文件输出转换为表格格式[不是html表格格式]

问题描述 投票:0回答:1

我想在bash脚本中将文本文件转换为MySQL类型适当的表格式。

现在,我将输出转储到一个文本文件[table.txt]中,然后逐行读取以按格式化顺序打印。

也想打印文件[toatl路径]的位置

但是我想要一个更好的解决方案。

#!/bin/bash
search_dir="$1"

path=$(ls -l $search_dir)

echo "$path" | awk -v OFS='\t''|''\t' 'BEGIN{print "          Owner         |      Size     |        Name     "}; {print"|" $3,  $5, $9 "\t""|"}' > table.txt


while IFS= read -r line; do
    echo "$line"
    echo "-----------------------------------------------------------------"
done < table.txt

Required output something like this

linux bash shell
1个回答
0
投票

尝试将此示例作为模板:

#/bin/bash header="Perm D Owner Group Size Date Name" data=$(ls -l|sed 's/total.*//') whiptail --title "Scrollbox" --scrolltext --msgbox "$header $data" 30 100

© www.soinside.com 2019 - 2024. All rights reserved.