如何在linux终端提示符下使用awk、sed、grep或cut将文本文件内容获取到表中
我需要像表格一样输出四列四行,即名称国家IP成本如何在linux终端提示符下使用awk、sed、grep或cut将文本文件内容获取到表中,awk,sed,grep,cut,Awk,Sed,Grep,Cut,我需要像表格一样输出四列四行,即名称国家IP成本 任何人都可以帮助我。您可以尝试列命令: cat raw.txt Name country IP Cost sam us 10.10.10.10 $250 jack India 10.10.10.12 $190 joy Australia 10.10.10.13 $230 christ canada 10.10.10.15 $190 jackson africa 10.10.10.20 $230 这里有一个老派的答案:——
任何人都可以帮助我。您可以尝试
列
命令:
cat raw.txt
Name country IP Cost
sam us 10.10.10.10 $250
jack India 10.10.10.12 $190
joy Australia 10.10.10.13 $230
christ canada 10.10.10.15 $190
jackson africa 10.10.10.20 $230
这里有一个老派的答案:——)
您可以使用
R
读取它,并使用xtable
包生成代码。您想将其输出到哪里?在贝壳里还是别的什么地方?我只想要贝壳里的桌子。
column -t file
Name country IP Cost
sam us 10.10.10.10 $250
jack India 10.10.10.12 $190
joy Australia 10.10.10.13 $230
christ canada 10.10.10.15 $190
jackson africa 10.10.10.20 $230
#!/bin/sh
# use tbl|nroff to make an ASCII table
# use sed to change multiple spaces into a single tab for tbl(1)
sed 's/ */\t/g' < raw.txt | awk '
BEGIN {
print ".TS" # beginning of table
print "allbox;" # allbox format
print "c s s s" # Table name format - centered and spanning 4 columns
print "lb lb lb lb" # bold column headers
print "l l l l." # table with 4 left justified columns. "." means repeat for next line
print "My Table" # Table name
}
{print} # print each line of 4 values
END {
print ".TE" # end of table
}' | tbl | nroff -Tdumb
┌─────────────────────────────────────────┐
│ My Table │
├────────┬───────────┬─────────────┬──────┤
│Name │ country │ IP │ Cost │
├────────┼───────────┼─────────────┼──────┤
│sam │ us │ 10.10.10.10 │ $250 │
├────────┼───────────┼─────────────┼──────┤
│jack │ India │ 10.10.10.12 │ $190 │
├────────┼───────────┼─────────────┼──────┤
│joy │ Australia │ 10.10.10.13 │ $230 │
├────────┼───────────┼─────────────┼──────┤
│christ │ canada │ 10.10.10.15 │ $190 │
├────────┼───────────┼─────────────┼──────┤
│jackson │ africa │ 10.10.10.20 │ $230 │
└────────┴───────────┴─────────────┴──────┘