Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 减少一些shell输出的最佳方法?_Bash_Shell_Awk_Grep - Fatal编程技术网

Bash 减少一些shell输出的最佳方法?

Bash 减少一些shell输出的最佳方法?,bash,shell,awk,grep,Bash,Shell,Awk,Grep,下面是命令cvt 1280 760的输出。我需要将第二行“之后的所有内容提取到行尾,以便在shell脚本的下一行中使用。这样做的最佳方式是什么 # 1280x760 59.91 Hz (CVT) hsync: 47.33 kHz; pclk: 78.75 MHz Modeline "1280x760_60.00" 78.75 1280 1344 1472 1664 760 763 773 790 -hsync +vsync 您可以使用sed sed -n 's/^[^"]*"[^"]*

下面是命令cvt 1280 760的输出。我需要将第二行
之后的所有内容提取到行尾,以便在shell脚本的下一行中使用。这样做的最佳方式是什么

# 1280x760 59.91 Hz (CVT) hsync: 47.33 kHz; pclk: 78.75 MHz
Modeline "1280x760_60.00"   78.75  1280 1344 1472 1664  760 763 773 790 -hsync +vsync
您可以使用sed

sed -n 's/^[^"]*"[^"]*"[[:blank:]]*//p' file
还是格雷普

grep -oP '^[^"]*"[^"]*"\s*\K.*' file
您可以执行此操作(通过
stdin
上的输入):

  • grep\“|
    ——仅限带有
  • -d\“
    -->是您的计价器吗
  • -f3-
    ——您需要第三个字段及其后面的所有内容

对于您的
文件

<file grep \" | cut -d\" -f3- 

使用
awk
可能会起作用:

awk -F'"[ ]+' '{print $2}' file
使用
-F
+
(一个或多个空格)
充当字段分隔符。

使用bash:

while IFS='"' read field1 field2 rest; do
    # do something with "$rest"
    echo "$rest"; 
done < <( cvt 1280 760 )
当IFS='”读取字段1字段2 rest;执行
#用“$rest”做点什么
回声“$rest”;
使用以下方法完成:

输出:

   78.75  1280 1344 1472 1664  760 763 773 790 -hsync +vsync

你想得到第一行吗?不,只是第二行的所有内容都从78.75开始(不一定总是78.75)。我试过像这样的cvt 1280 760 | cut-d\“-f3-但它只是返回了完整的输出?对于你的输入,in给了我“78.75 1280 1344 1472 1664 760 763 773 790-hsync+vsync”,即——第二行之后的所有内容
while IFS='"' read field1 field2 rest; do
    # do something with "$rest"
    echo "$rest"; 
done < <( cvt 1280 760 )
#!/bin/bash
s='Modeline "1280x760_60.00"   78.75  1280 1344 1472 1664  760 763 773 790 -hsync +vsync'
pat='[^"]*"[^"]*"(.*)'
[[ $s =~ $pat ]]
echo "${BASH_REMATCH[1]}"
   78.75  1280 1344 1472 1664  760 763 773 790 -hsync +vsync