grep 文本过滤命令_grep过滤指定字段-CSDN博客

介绍

grep 是 Linux 和类 Unix 系统中一个强大的文本搜索命令,它全称是 “Global Regular Expression Print”。其主要功能是在指定文件或输出中查找包含特定模式(通常是一个正则表达式)的行,并将匹配的行打印出来。

基本使用

  1. 基本语法:

    1
    grep [选项] 搜索模式 文件或目录
  2. 搜索模式:

    • 可以是简单的字符串,也可以是正则表达式。
    • 使用 -E--extended-regexp 选项启用 Perl 正则表达式。
    • 使用 -P--perl-regexp 选项启用更复杂的支持 PCRE(Perl 兼容正则表达式)。
  3. 选项:

    • -i--ignore-case:忽略大小写。
    • -v--invert-match反向选择,打印不匹配的行
    • -l--files-with-matches:只显示包含匹配项的文件名。
    • -n--line-number:在输出每行前显示行号。
    • -r--recursive:递归搜索目录中的文件。
    • -w--word-regexp:仅匹配整个单词。
    • -c--count:只统计匹配的行数。
  4. 使用示例:

    • 查找包含 “example” 的行:grep example file.txt
    • 忽略大小写查找 “example”:grep -i example file.txt
    • 在当前目录及其子目录中查找 “example”:grep -r example .
阅读全文 »

参考: ‘scopedTarget.requestScopedBean’: Scope ‘request’ is not active for the current thread - 知乎

问题描述

1
2
3
4
5
org.springframework.beans.factory.support.ScopeNotActiveException: 
Error creating bean with name 'scopedTarget.requestScopedBean':
Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException:
No thread-bound request found:
Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

错误原因:RequestScope的Bean的作用域是限定在当前线程内的,使用多线程开启子线程,子线程是无法获得RequestScope的Bean的值的,所以如果子线程涉及的代码里如果用到父线程中的RequestScope的Bean,就因为这个Bean=null而抛出如上异常。

解决方案

设置上下文到子线程

1
2
3
4
5
6
7
8
9
10
private CompletableFuture<String> testTask() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
return CompletableFuture.supplyAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
return "success";
}).exceptionally(e -> {
log.error("[{}] error occurred: {}", requestScopeBean.getRequestId(), e.getMessage());
return e.getMessage();
});
}
阅读全文 »

简述

操作的主要思路为:

  • 在不删除源文件的基础上,将源文件备份
  • 下载最新centos8国内的yum源文件
  • 更换地址

执行

  1. 进入root,切换至yum.repos.d目录:cd /etc/yum.repos.d/
  2. 创建新文件夹并将源文件备份为repo.bak: mkdir backup && mv *repo backup/
  3. 下载国内yum源文件:curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
  4. 更新下载yum源地址
    1
    2
    3
    4
    sed -i -e"s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*

    sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*

  5. 生成缓存:yum clean all && yum makecache
阅读全文 »

转载自:Proxmox VE 的 LXC 容器安装 NTP 时间同步 — 董仁文的博客 (dongrenwen.github.io)

CentOS 系统修改 NTP 时间同步

修改时区

1
2
# 修改时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装客户端

1
2
# 安装 ntp 客户端
yum install ntp ntpdate -y

修改配置文件 /etc/ntp.conf 中和 NTP 服务相关部分

1
2
3
4
5
6
7
8
9
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

# Use Aliyun's ntp server as a fallback.
server ntp.aliyun.com

将 NTP 服务设置成为开机自启

1
2
# 将 ntp 服务设置成为开机自启
systemctl enable ntpd
阅读全文 »