.htaccess我今天更新了 Apache(至 2.4.56-1) ,以前可以正常工作的大量重写现在出现了 AH10411 错误,与查询中的空格有关。我正在努力寻找“适当”的解决方案。
用户单击一个链接,例如<a href='FISH%20J12345.6-78919'>clickme</a>- 您可以看到链接 URL 中的空格已被编码为%20。
.htaccess相关服务器目录中的文件包含并执行以下相关指令:
RewriteRule ^(FISH\s*J[0-9\.]+-?\+?[0-9]+)$ myPage.php?sourceName=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
(在上面我检查的是空格,而不是%20,因为浏览器似乎在符合此规则之前将其转换为空格)。
在我更新 Apache 之前,这一直有效;现在用户收到 403 错误,我的 Apache 错误日志报告:
AH10411:重写的查询字符串包含控制字符或空格
这似乎是一个新错误,因为谷歌搜索什么也没找到!
编辑我的页面(例如)将空格更改为下划线并正确处理它并不是真正的选择,因为该设计旨在支持用户能够直接使用他们关心的对象的名称输入 URL。到目前为止,我发现的唯一解决方法有点难看,即在正则表达式中分别捕获源名称的两个部分,因此:
RewriteRule ^(FISH)\s*(J[0-9\.]+-?\+?[0-9]+)$ myPage.php?sourceName=$1+$2 [L,QSA]
^ ^ ^^^
Run Code Online (Sandbox Code Playgroud)
(我$1%20$2最后尝试了一下,也导致了同样的错误。)
对此有更好的解决方案吗?即,当 URL 位于我想要捕获并作为参数传递给底层页面的字符串中时,我“应该”如何处理 URL 中的空格情况?
这是test.txt:
0x01,0xDF,0x93,0x65,0xF8
0x01,0xB0,0x01,0x03,0x02,0x00,0x64,0x06,0x01,0xB0
0x01,0xB2,0x00,0x76
Run Code Online (Sandbox Code Playgroud)
如果我运行
awk -F, 'BEGIN{OFS=","}{$2="";print $0}' test.txt
结果是:
0x01,,0x93,0x65,0xF8
0x01,,0x01,0x03,0x02,0x00,0x64,0x06,0x01,0xB0
0x01,,0x00,0x76
Run Code Online (Sandbox Code Playgroud)
$2 没有被删除,它只是变空了。我希望在打印 $0 时,结果是:
0x01,0x93,0x65,0xF8
0x01,0x01,0x03,0x02,0x00,0x64,0x06,0x01,0xB0
0x01,0x00,0x76
Run Code Online (Sandbox Code Playgroud) I have the following text input:
lorem <a> ipsum <b> dolor <c> sit amet,
consectetur <d> adipiscing elit <e>, sed
do eiusmod <f> tempor
incididunt ut
Run Code Online (Sandbox Code Playgroud)
As seen in the text, the appearances of <?> is not fixed and can appear 0 or multiple times on the same line.
Only using awk I need to output this:
<a> <b> <c>
<d> <e>
<f>
Run Code Online (Sandbox Code Playgroud)
I tried this awk script:
awk '{
match($0,/<[^>]+>/,a); // fill array a with matches
for …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 shell 脚本将文件中的句子拆分为单独的行。
现在我想用 !, 分割字符串。或者 。. 输出应该是这样的:
我想从my_text.txt读取并包含的文件
you want to learn shell script? First, you want to learn Linux command! then. you can learn shell script.
现在我想用“!”或“?”或“。”分割字符串。输出应该是这样的:
Run Code Online (Sandbox Code Playgroud)you want to learn shell script First, you want to learn Linux command then you can learn shell script
我使用了这个脚本:
while read p
do
echo $p | tr "? ! ." "\n "
done < my_text.txt
Run Code Online (Sandbox Code Playgroud)
但输出是:
你想学习shell脚本
首先,你想学习Linux命令然后你可以学习shell脚本
有人可以帮忙吗?
简短的问题描述:我在 Redhat Linux 和 Ubuntu 操作系统上创建了两个新的 AWS EC2 服务器实例。我试图通过 Putty 通过 SSH 登录它,但出现错误(详细错误有问题)。这只是一个简短的描述。
详细问题描述:我在创建Ubuntu 20 OS版本的免费层Amazon EC2(弹性计算云)服务器后生成了一个新的.pem文件。然后我PuttyGen在我的 Windows-10 操作系统电脑中使用了软件当尝试通过腻子登录时,它给了我一个错误,如下面的错误描述所示,因此我无法登录到 aws 机器,我进一步调查了在这个自我回答的问题中详细提到了问题和故障排除步骤的所有细节(欢迎其他建议/解决方案)。
错误描述:
"Server refused our key" 在终端 AND "NO supported authentication method available(server sent:public ke;gssapi-with-mic)"
我有一个由制表符分隔的两列文件,如下所示:
OG0000000 PF03169,PF03169,PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,PF00083,PF07690,PF00083,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF00690,
OG0000005 PF00012,PF01061,PF12697,PF00012,
Run Code Online (Sandbox Code Playgroud)
我只想删除第二列中的重复字符串,而不更改第一列中的任何内容,以便我的最终输出如下所示:
OG0000000 PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF00690,
OG0000005 PF00012,PF01061,PF12697,
Run Code Online (Sandbox Code Playgroud)
我尝试使用 awk 来启动它。
awk 'BEGIN{RS=ORS=","} !seen[$0]++' file.txt
Run Code Online (Sandbox Code Playgroud)
但我的输出看起来像这样,如果重复的字符串首先出现,则仍然存在一些重复项。
OG0000000 PF03169,PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,PF07690,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF00690,
OG0000005 PF00012,PF01061,PF12697,PF00012,
Run Code Online (Sandbox Code Playgroud)
我意识到问题是因为 awk 抓取的第一行是第一个逗号之前的所有内容,但我对 awk 命令仍然很粗糙,无法弄清楚如何在不弄乱第一列的情况下解决这个问题。提前致谢!
我遇到了一个问题(关于 SO 本身),其中 OP 必须对 Input_file(s) 本身进行编辑和保存操作。
我知道对于单个 Input_file 我们可以执行以下操作:
awk '{print "test here..new line for saving.."}' Input_file > temp && mv temp Input_file
Run Code Online (Sandbox Code Playgroud)
现在假设我们需要以相同类型的文件格式进行更改(假设这里是 .txt)。
我对这个问题的尝试/想法:它的方法是通过 .txt 文件的 for 循环,调用 singleawk是一个痛苦且不推荐的过程,因为它会浪费不必要的 cpu 周期,并且对于更多数量的文件,它会更多减缓。
那么在这里可以做什么来使用awk不支持就地选项的非 GNU 对多个文件执行就地编辑。我也经历过这个线程使用 awk 保存修改,但对于非 GNU awk 的恶习和在awk其内部更改多个文件没有什么意义,因为非 GNU awk 将无法inplace选择它。
注意:为什么我要添加bash标签,因为在我的回答部分中,我使用 bash 命令将临时文件重命名为它们的实际 Input_file 名称,因此添加了它。
编辑:根据 Ed sir 的评论,在此处添加示例示例,尽管此线程代码的用途也可用于通用就地编辑。
示例 Input_file(s):
cat test1.txt
onetwo three
tets testtest
cat test2.txt
onetwo …Run Code Online (Sandbox Code Playgroud) 如何用四个字母反转sed?
例如:
the year was 1815.
Run Code Online (Sandbox Code Playgroud)
反向:
the raey was 5181.
Run Code Online (Sandbox Code Playgroud)
这是我的尝试:
cat filename | sed's/\([a-z]*\) *\([a-z]*\)/\2, \1/'
Run Code Online (Sandbox Code Playgroud)
但它并不像我预期的那样有效.
nginx 访问.log。它由 1) 空格 2) [ ] 和 3) 双引号分隔。
::1 - - [12/Oct/2021:15:26:25 +0530] "GET / HTTP/1.1" 200 1717 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
::1 - - [12/Oct/2021:15:26:25 +0530] "GET /css/custom.css HTTP/1.1" 200 202664 "https://localhost/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
Run Code Online (Sandbox Code Playgroud)
解析后它应该看起来像
$1 = ::1
$4 = [12/Oct/2021:15:26:25 +0530] or 12/Oct/2021:15:26:25 +0530
$5 = "GET / HTTP/1.1"
$6 = 200
$7 = 1717
$8 = "-"
$9 = "Mozilla/5.0 …
我正在尝试以 txt 格式查找字符串,每次找到它时都会查找特定字符串以更改为另一个字符串并避免读取该行的第一个序列。
想象一下接下来的十六进制txt:
0000 09 06 07 04 00 00 01 00 1d 03 4b 2c a1 2a 02 01
0010 b7 09 01 47 30 22 a0 0a 80 08 33 04 03 92 22 14
0020 17 f0 a1 0b 80 00 81 00 84 01 00 86 00 85 00 83
0030 07 91 94 71 06 00 07 19
0000 09 06 07 04 00 00 01 00 2b 03 4b 27 a1 25 02 …Run Code Online (Sandbox Code Playgroud)