AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题

问题[string](computer)

Martin Hope
Random Guy
Asked: 2022-07-22 04:15:24 +0800 CST

如何从bash中的字符串中提取特定部分

  • 5

我得到了这个输出:

Duration: 00:03:27.05, start: 0.000000, bitrate: 336 kb/s

我想00:03:27.05从整个字符串中提取(值可以更改)。

到目前为止,我已经尝试过:

String="Duration: 00:03:27.05, start: 0.000000, bitrate: 336 kb/s"

String="${String#*:}"
String="${String%,*,*}"
echo $String

它给出了预期的结果,但在这里我必须String两次声明变量并且必须分别剪切字符串的特定部分。

所以我只想知道一种最简单直接的方法来做到这一点。

在此先感谢您的帮助:)

bash string
  • 3 个回答
  • 112 Views
Martin Hope
Paul Schuldesz
Asked: 2021-04-10 03:53:30 +0800 CST

如何在鱼壳中将函数参数作为字符串传递

  • 5

Octave 有一个 --eval 选项,它接受像“sqrt(4)”这样的字符串并输出“ans = 2”。我想创建一个将 a 参数作为字符串传递的函数,所以我可以这样调用它:

calc sqrt(4)

相当于:

octave --eval "sqrt(4)"

我写了一个这样的简单函数:

function calc --wraps octave
   octave --eval "$argv"
end

这没用。

输出:

$calc sqrt(4)
fish: Unknown command: 4
in command substitution
fish: Unknown error while evaluating command substitution
calc sqrt(4)
shell-script string
  • 1 个回答
  • 259 Views
Martin Hope
aliaz
Asked: 2021-01-21 01:07:38 +0800 CST

Excel:从文本字符串中提取项目编号(不同的位置和长度)

  • 5

在 Excel 电子表格中,我有一列包含项目主数据(类型、项目编号、地址、主题等)的混合文本字符串。我需要从这个字符串中自动提取项目编号。一个问题是数字位于字符串中的不同位置。我猜这使得使用 =MID() 变得很困难。另一个问题是数字的长度不同。

3 个字符串的示例:

invoice no2014-0406-1 Main Street, John Nelson, 购置
税 projno 2015-0021 拒绝申请
gl oldroad 10 case 2014-0306-003 HUKO, JFR

从我需要提取的字符串中:

2014-0406-1
2015-0021
2014-0306-003

我希望这可以自动完成。在此先感谢您的帮助!:)

microsoft-excel string
  • 1 个回答
  • 150 Views
Martin Hope
mapman
Asked: 2020-10-16 12:33:47 +0800 CST

如何在 Notepad++ 中将字符串行之间的文本行组合成一行代码,同时保留字符串分隔符之外的行?

  • 6

我在 Notepad++ 中有 100 页来自 pdf 文件的文本格式的页面。文件中的每一页都有不同数量的行,但它们都包含读取“TARGET_LINE”和“LAST_LINE”的行。在这两个字符串之间是不同的文本行。虽然“TARGET_LINE”和“LAST_LINE”总是出现,但中间的行数不同 - 有时中间有四行,如下所示,其他时候有两行,等等。

我需要一个搜索和替换公式,它 1) 保留 TARGET_LINE 上方的行,但 2) 将“TARGET_LINE”和“LAST_LINE”之间的所有行合并到一个单独的代码行中,包括前缀和后缀行,这样 . ..

abc
123
xyz
TARGET_LINE, 
second line lfutdytdyt
3rd line x;lkhr;lkj
fourth klufhkgfk
5th ;lkjk;lkj;lj
LAST_LINE,
def
456
TARGET_LINE, 
lfutdytdyt
klkrjtlkj
LAST_LINE,

,,, 变为:

abc
123
xyz
TARGET_LINE, second line lfutdytdyt 3rd line x;lkhr;lkj fourth klufhkgfk 5th ;lkjk;lkj;lj LAST_LINE,
def
456
TARGET_LINE, lfutdytdyt klkrjtlkj LAST_LINE,

(前一行之间最好使用逗号,但不是必需的):

提前感谢您的时间和帮助。

notepad++ string
  • 1 个回答
  • 697 Views
Martin Hope
mapman
Asked: 2020-10-16 09:37:39 +0800 CST

如何在 Notepad++ 中将不同的多行文本组合成一行代码,并具有共同的开始和结束字符串?

  • 6

我在 Notepad++ 中有 1000 行文本,其中多个行实例以“FIRST_LINE”开头,然后是不同数量的行,并以名为“LAST_LINE”的行结尾。虽然“FIRST_LINE”和“LAST_LINE”总是出现,但中间的行没有标准的开头,也没有固定的中间行数。例如,有时中间有四行,如下所示,有时有两行,等等。

我需要一个搜索和替换公式来将“FIRST_LINE”、“LAST_LINE”和中间的所有行组合成单独的文本行,这样:

FIRST_LINE, 

second line lfutdytdyt

3rd line x;lkhr;lkj

fourth klufhkgfk

5th ;lkjk;lkj;lj

LAST_LINE,


FIRST_LINE, 

lfutdytdyt

klkrjtlkj

LAST_LINE,

变成:

FIRST_LINE, second line lfutdytdyt, 3rd line x;lkhr;lkj, fourth klufhkgfk, 5th ;lkjk;lkj;lj, LAST_LINE,

FIRST_LINE, lfutdytdyt, klkrjtlkj, LAST_LINE,

(前一行之间最好使用逗号,但不是必需的):

提前感谢您的时间和帮助。

notepad++ string
  • 1 个回答
  • 193 Views
Martin Hope
mapman
Asked: 2020-10-16 07:08:57 +0800 CST

如何在破折号后的第一个字母处创建新的换行符?

  • 7

多年来我一直在使用这个很棒的网站,但是经过数小时的搜索后,我无法弄清楚如何在 Notepad++ 中执行以下操作。于是我开了一个账户,恭敬地提出以下要求:

我有数千条记录,如下所示,其中破折号位于各种马名和记录(一行文本)之前:

Canland Hall 3,1:57 ------Father Patrick 3,1:50.2f  ----------------Enjoy Lavec 3,1:52 ----Gala Dream -------------------------------Maple Frosting

我需要创建以每匹马的名字开头的新行。在“查找内容”中使用-[A-Z]我可以识别马名的破折号和第一个字母(例如,上面“父亲”中的“-F”),但我不知道如何创建一个以马名开头的新行(没有破折号)。

我需要什么(至少):

Canland Hall 3,1:57 

Father Patrick 3,1:50.2f  ----------------

Enjoy Lavec 3,1:52 

Gala Dream -------------------------------

Maple Frosting

我想要的(没有破折号):

Canland Hall 3,1:57

Father Patrick 3,1:50.2f  

Enjoy Lavec 3,1:52 

Gala Dream 

Maple Frosting

提前感谢您的时间和帮助。

notepad++ string
  • 2 个回答
  • 54 Views
Martin Hope
I Z
Asked: 2020-09-25 14:30:26 +0800 CST

Excel 2016:如何在另一列的一列单元格中查找所有超字符串匹配项?

  • 5

我在 Excel 2016 中有两列字符串。A 列很长。B栏很短。我需要:

  1. 循环遍历 col B 中的所有单元格
  2. 对于每个单元格,我需要找到 col A 中的所有单元格,其中 B 中的字符串是子字符串。因此,如果 B 中的单元格是“foo”,并且 A 的第 5 行有“fooA”,第 25 行有“Bfoo”,我需要找到它们,并且只有那些
  3. 我需要以某种方式显示所有匹配项。也就是说,对于 BI 中的每个单元格,都需要快速查看来自 A 的所有超字符串匹配

我怎样才能做到这一点?

蒂亚!

microsoft-excel-2016 string
  • 1 个回答
  • 400 Views
Martin Hope
Brian
Asked: 2020-04-14 20:06:27 +0800 CST

Powershell:评估表示为字符串的数学表达式

  • 5

在 PowerShell 中,如何计算存储为字符串的数学表达式?如何让 PowerShell 评估以下内容:

C:\> $a="30000/1001"
C:\> $a

30000/1000
C:\>

期望的输出:

C:\> $a="30000/1001"
C:\> <some command>

29.97002997003
C:\>

在 Linux 中,我可以执行以下操作(基本上是我想在 PowerShell 中完成的):

user@computer:/path# a="30000/1001"
user@computer:/path# echo "scale=5; $a" | bc
29.97002
powershell string
  • 1 个回答
  • 704 Views
Martin Hope
user115930
Asked: 2020-03-12 21:34:12 +0800 CST

如何使用 awk 或像其他人一样拆分不规则的空白字段?

  • 5

我想将数据拆分如下:

$1       $2           $3               $4  $5  $6 $7       $8   .........
---------------------------------------------------------------------------------------------------
root     tty5                          Wed Dec 18 13:42:28 2019   still logged in             
                      ~~~~~~~~~~~~~    ~~~
                      ^                ^
root     tty5                          Wed Dec 18 11:23:20 2019 - Wed Dec 18 11:24:47 2019  (00:01)    
john     pts/2        xx.xxx.xx.xxx    Tue Sep  3 10:11:31 2019 - Tue Sep  3 10:21:18 2019  (00:09)    
john     pts/3        xx.xxx.xx.xxx    Mon Sep  2 14:42:29 2019 - Mon Sep  2 14:57:33 2019  (00:15)    
john     pts/2        xx.xxx.xx.xxx    Mon Sep  2 14:40:03 2019 - Mon Sep  2 14:45:27 2019  (00:05)    
john     pts/2        xx.xxx.xx.xxx    Mon Sep  2 13:52:09 2019 - Mon Sep  2 14:34:12 2019  (00:42)    
john     pts/3        xx.xxx.xx.xxx    Mon Sep  2 13:14:39 2019 - Mon Sep  2 14:03:24 2019  (00:48)    
john     pts/2        xx.xxx.xx.xxx    Mon Sep  2 13:08:11 2019 - Mon Sep  2 13:23:16 2019  (00:15)    
john     pts/2        xx.xxx.xx.xxx    Mon Sep  2 10:22:27 2019 - Mon Sep  2 11:10:48 2019  (00:48)    
john     pts/2        xx.xxx.xx.xxx    Fri Aug 30 17:25:19 2019 - Fri Aug 30 17:33:34 2019  (00:08)    
john     pts/2        xx.xxx.xx.xxx    Wed Aug 28 10:43:56 2019 - Wed Aug 28 10:52:48 2019  (00:08)    
john     pts/2        xx.xxx.xx.xxx    Tue Aug 27 16:59:30 2019 - Tue Aug 27 17:52:50 2019  (00:53)    
john     pts/2        xx.xxx.xx.xxx    Tue Aug  6 11:06:46 2019 - Tue Aug  6 11:12:05 2019  (00:05)    
john     pts/2        xx.xxx.xx.xxx    Tue Aug  6 10:48:39 2019 - Tue Aug  6 11:01:46 2019  (00:13)    
john     pts/2        xx.xxx.xx.xxx    Tue Aug  6 10:38:18 2019 - Tue Aug  6 10:43:18 2019  (00:05)    
john     pts/2        xx.xxx.xx.xxx    Tue Aug  6 10:28:02 2019 - Tue Aug  6 10:36:04 2019  (00:08)    
john     pts/2        xx.xxx.xx.xxx    Fri Aug  2 14:24:00 2019 - Fri Aug  2 14:24:16 2019  (00:00)    
root     tty5                          Fri Aug  2 14:21:30 2019 - Fri Nov 22 11:03:20 2019 (111+20:41) 
root     tty5                          Fri Jul 26 11:02:17 2019 - Fri Jul 26 11:03:58 2019  (00:01)    
john     pts/3        xx.xxx.xx.xxx    Thu Jul 25 16:24:44 2019 - Thu Jul 25 16:33:36 2019  (00:08)    
john     pts/2        xx.xxx.xx.xxx    Thu Jul 25 16:08:41 2019 - Thu Jul 25 16:33:53 2019  (00:25)   

但是,如果 $3 为空,我无法正确获得 $3 和下一个字段的值。例如:

$ last -F | grep -E 'tty|pty|pts' | awk '{print $3}'
Wed                 <- not correct
Wed                 <- not correct
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
xx.xxx.xx.xxx
Fri                 <- not correct
Fri                 <- not correct
xx.xxx.xx.xxx
xx.xxx.xx.xxx

如何使用 awk 或类似的命令行工具正确解析它?

linux string
  • 1 个回答
  • 88 Views
Martin Hope
Supr0
Asked: 2020-03-03 11:57:11 +0800 CST

字符串操作 - 在某个单词之后获取部分

  • 5

背景:虽然我认为 Fail2Ban 是保护 Apache 等子系统的好方法,但将所有信息汇总在一起需要大量工作。所以我正在编写一个 BASH 脚本来为我做这件事。

我需要将fail2ban-client的' get '选项放在一个数组中..

到目前为止,我使用以下方法隔离了这些:f2b_opts_cmd="$(sudo fail2ban-client --help | grep -i 'get <jail>' | grep -vw 'act')"

在命令行上,它看起来像:

get <JAIL> logpath                       gets the list of the monitored
get <JAIL> logencoding                   gets the encoding of the log files
get <JAIL> journalmatch                  gets the journal filter match for
get <JAIL> ignoreself                    gets the current value of the
get <JAIL> ignoreip                      gets the list of ignored IP
get <JAIL> ignorecommand                 gets ignorecommand of <JAIL>
get <JAIL> failregex                     gets the list of regular
get <JAIL> ignoreregex                   gets the list of regular
get <JAIL> findtime                      gets the time for which the filter
get <JAIL> bantime                       gets the time a host is banned for
get <JAIL> datepattern                   gets the patern used to match
get <JAIL> usedns                        gets the usedns setting for <JAIL>
get <JAIL> maxretry                      gets the number of failures
get <JAIL> maxlines                      gets the number of lines to buffer
get <JAIL> actions                       gets a list of actions for <JAIL>

但是,变量看起来像:

get <JAIL>logpath 获取被监控的列表 get <JAIL>logencoding 获取日志文件的编码 get <JAIL>journalmatch 获取日志过滤器匹配 get <JAIL>ignoreself 获取当前值 get <JAIL>ignoreip 获取忽略的 IP 列表 get <JAIL>ignorecommand 获取 ignorecommand of <JAIL>get <JAIL>failregex 获取常规获取<JAIL>列表 ignoreregex 获取常规获取列表<JAIL>findtime 获取过滤器获取<JAIL>bantime 获取主机被禁止的时间获取 datepattern 获取模式.. etc.etc。

但我需要有类似的东西:

f2b_opts=(logpath logencoding journalmatch ignoreself ignoreip ignorecommand failregex ignoreregex findtime bantime datepattern usedns maxretry maxlines actions)  

部分后面的单词怎么读<JAIL>?

经过几天搜索这个论坛和其他网站,仍然没有找到解决这个问题的方法。这里的复杂因素是“小于”和“大于”符号以及原始字符串中有多个“JAIL”单词的事实(参见示例)。

bash string
  • 1 个回答
  • 65 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve