如何从shell脚本中的字符串中提取路径 [英] how to extract path from string in shell script
本文介绍了如何从shell脚本中的字符串中提取路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从字符串中提取路径
i need to extract path from string
例如
title="set key invert ; set bmargin 0 ; set multiplot ; set size 1.0 , 0.33 ; set origin 0.0 , 0.67 ; set format x "" ; set xtics offset 15.75 "1970-01-01 00:00:00" , 31556736 ; plot "/usr/local/lucid/www/tmp/20171003101438149255.dat" using 1:5 notitle with linespoints ls 2'"
则预期输出应为
/usr/local/lucid/www/tmp/20171003101438149255.dat
使用awk或grep
using awk or grep
推荐答案
带grep
的短正则表达式:
grep -oP 'plot "\K[^"]+' <<< $title
/usr/local/lucid/www/tmp/20171003101438149255.dat
这篇关于如何从shell脚本中的字符串中提取路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文