查找以s preadsheet文本一号线并获得第2列 [英] Find text line1 in spreadsheet and get column 2

查看:145
本文介绍了查找以s preadsheet文本一号线并获得第2列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图表明旁边我发现以s predsheet.xls

I'm trying to show the field next to the name that I find with awk command in spredsheet.xls

我有这种情况;

  **Column1**               *Column2* 

  **PIPPO**    *pippo@gmail.com darth@gmail.com*
  **PLUTO**    *pluto@gmail.com duck@gmail.com*
  **WATER**    *drink@gmail.com water@gmail.com*

我如何搜索一个单词列1和第2栏显示的内容?

how do I search for a word in column 1 and display the contents in column 2?

awk '$1 == "PIPPO"' spreadsheet.xls

此命令显示:

PIPPO    pippo@gmail.com darth@gmail.com


更新

这是我的code ----列1(PIPPO,冥王星,水)和awkvar是一回事----


Update

this is my code ---- Column1 (PIPPO, PLUTO, WATER) and awkvar is the same thing----

for fullname in /*.zip; do 
filename="${fullname##*/}" 
awkvar=$(echo $filename | cut -d_ -f2-2) 
awk -v var="$awkvar" '{print $2,$3}' spreadsheet.xls 
done 

但这不起作用。我如何把一个模式变量AWK?

but this not work. How do I put a pattern variable in awk?

更新2

我有更新列表XLS用逗号隔开

i have update list xls with comma separated

FIELD1,皮波@ gmail.com,达思@ gmail.com结果
FIELD1,皮波@ gmail.com,达思@ gmail.com,sampei @ gmail.com

FIELD1,pippo@gmail.com,darth@gmail.com
FIELD1,pippo@gmail.com,darth@gmail.com,sampei@gmail.com

output=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3,$4} spreadsheet.txt)

但在输出的开头awk中删除一些信件

but awk delete some letters at the beginning of the output

echo "$output"


  • ippo@gmail.com darth@gmail.com

  • pippo@gmail.com darth@gmail.com sampei@gmail.com

  • 但如果我删除了$ 4'/ p>

    but if i remove $4

    output=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3} spreadsheet.txt)
    
    echo "$output"
    

    这是一号线而不是2号线正确显示:

    it is correct display for line1 but not for line2:


    • pippo@gmail.com darth@gmail.com

    • pippo@gmail.com darth@gmail.com

    我在做什么错了?

    推荐答案

    您可以使用以下方法:

    awk '$1=="PIPPO" {print $2}' file
    

    这将输出:

    pippo@gmail.com
    

    格式我也不清楚,所以这取决于它是如何,你可能需要 {打印$ 2,$ 3}

    作为意见的基础上,更新后的code,你可以用它来使用里面的bash的VAR说 AWK

    As said in comments, based on your updated code you can use this to use the bash var inside awk:

    awk -v var="$awkvar" '$1==var {print $2,$3}' spreadsheet.xls
    

    这篇关于查找以s preadsheet文本一号线并获得第2列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆