bash - 使用 cut 和 bash
问题描述
我正在尝试切断这条线
`Cycling-Tour.Of.Great.Britain.Results-Cycling.txt`
to
`cycling-tour.of.great.britain.txt`
所以我希望在 bash 脚本中使用 cut 删除部分 .Results-cycling ,但我没有尝试过
`txtname=$(echo "$txtname" | tr '[A-Z]' '[a-z]' | cut -d "-" -f2,11)`
它将大写字母排序,但它删除了大部分行。任何帮助将不胜感激
解决方案
bash
有不错的字符串解析。有一些选项不会产生这么多子进程。
利用
$: declare -l txtname
首先,您不必再担心大小写了。
$: txtname=Cycling-Tour.Of.Great.Britain.Results-Cycling.txt
$: IFS=. read a b c d x e <<< "$txtname"
$: echo "$a.$b.$c.$d.$e"
cycling-tour.of.great.britain.txt
要不就
echo "${txtname/results-cycling.}"
cycling-tour.of.great.britain.txt
如果你只是想使用cut
-
$: cut -d . -f 1-4,6 <<< "${txtname,,}"
cycling-tour.of.great.britain.txt
推荐阅读
- jsp - 如何在 OpenAM 中获取标头属性?
- python - 如何使用 Python(不使用 PySpark)将 pandas 数据框插入到现有的 Hive 外部表中?
- javascript - 根据 csv 文件中的 x 轴值绘制 Y 轴数据:Highcharts
- html - 如何在dataview中制作水平滚动条
- c# - 通过代理使用 KeyVaultClient
- vb.net - 在 rdlc 报告中将数字转换为 Word
- apache - Webpack/Apache - 浏览时看不到“dist”文件夹
- java - 使用 java 套接字通过网络发送屏幕截图图像
- php - PHP 文件上传 move_uploaded_file
- c++ - cppcheck:使用/typedef 的语法错误