gpt4 book ai didi

Bash 脚本 : Delete characters in string up to and including a phrase?

转载 作者:行者123 更新时间:2023-11-29 09:43:47 24 4
gpt4 key购买 nike

我有一个用于隐藏 X11 窗口的 bash 脚本。我希望能够找到鼠标所在的窗口并取消映射该窗口。

使用 xdotool 我找到了找到窗口 ID 的方法:

$ xdotool 获取鼠标位置
x:392 y:344 屏幕:0 窗口:54799020

我想将此行缩减为 54799020
(我想删除包括 window: 在内的所有内容。)

有没有办法做到这一点?我对 trsed 的经验很少。我以前使用 sed 删除文本,但我还需要删除鼠标坐标,它们并不总是相同的。

最佳答案

awk with field seperator : 和 grab column 4

您可以使用这样的 awk 脚本

#!/bin/awk
BEGIN { FS=":";}
print $5

或在命令行上运行它。

awk -F':' '{print $5}' file

在你的情况下

xdotool getmouselocation | awk -F':' '{print $5}' -

将它设置为一个变量(这可能是你正在做的)

WINDOWLOC=`xdotool getmouselocation | awk -F':' '{print $5}' -`

WINDOWLOC=$(xdotool getmouselocation | awk -F':' '{print $5}' -)

关于Bash 脚本 : Delete characters in string up to and including a phrase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23458080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com