将字符串附加到 shell 中的输出 [英] Append string to output in shell

查看:25
本文介绍了将字符串附加到 shell 中的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将/*"附加到以下 cmd 的输出路径:

I want to append "/*" to the output paths from the below cmd:

找到/home/mba/Desktop/-type d -name "logs"

我尝试使用 sed 正则表达式如下:

I tried to use sed regex as below:

find/home/mba/Desktop/-type d -name "logs" |sed -e 's/(^.)/\1//'

find /home/mba/Desktop/ -type d -name "logs" | sed -e 's/(^.)/\1//'

但我收到以下错误:sed: -e 表达式 #1, char 14: `s' 的未知选项

But I got the below error: sed: -e expression #1, char 14: unknown option to `s'

提前致谢.

推荐答案

这是一个使用 awk 的可行解决方案:

This is a working solution using awk:

find /home/mba/Desktop/ -type d -name "logs" | awk '{ print $1"/*" }'

或者使用sed:

find /home/mba/Desktop/ -type d -name "logs" | sed 's/$/\/\*/'

这篇关于将字符串附加到 shell 中的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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