我有一个很大的 csv 文件(120GB),如下所示:
"JE",865438083645,2012-12-05T23:07:36.000Z,24,"NQ",142,"658_55525",475035504705
"JE",875619112765,2012-12-05T23:58:04.000Z,4,"PG",144,"219_9221",835399289335
"JE",125495251245,2012-12-05T18:16:06.000Z,206,"PLJE",153,"763_60771",445355650435
Run Code Online (Sandbox Code Playgroud)
我想从第七列中的值中删除下划线和引号(例如,"658_55525"变为65855525)。我正在使用的数据库的导入工具不允许在导入时转换或操作文件。
从命令行执行此操作的有效方法是什么?
当我在Linux终端中运行任意命令时,有没有办法抑制包含特定句子的输出消息?
我试过
./mycommand | grep -v "I dont want to see this"
Run Code Online (Sandbox Code Playgroud)
但消息仍然存在。
我有一句话:
171211 22043707 21641 xxxx xxxxxxx From (,,xxxx,xxxx) Vxxxx1: xxxxxx
171212 13441585 417 xxxx xxxxxxxx Server manager informed of process termination, pinfo = x,0000032585 13:44:15
Run Code Online (Sandbox Code Playgroud)
171211 22043707问题是和之间的空间21641有所不同。我想将其替换为一个空格。我该怎么做呢?哪条sed命令可以匹配一个或多个空格?
我正在寻找有关创建脚本以查找和替换文本文件中的特殊字符的一些指导。
我想出了这段伪代码,但填补空白有点困难:
CP按换行符查找和替换。Mr. Mime(带空格)& 替换Mr.Mime(不带空格)%并替换为空(也就是忽略它)“查找”代表“查找所有实例”。
我一直在研究sed,但我似乎无法找到如何处理这些特殊字符。任何想法都非常感谢。
编辑:正如特此所问的输入的一小段:
CP 1593
SSS
Sudowoodo?
ATK DEF STA IV
15 15 15 100.0%
counter
rock slide
CP 1262
SSS
Tangrowth?4
ATK DEF STA IV
15 15 15 100.0%
vine whip
grass knot
CP 1077
SSS
Mr. Mime?
ATK DEF STA IV
15 15 15 100.0%
confusion
psychic
Run Code Online (Sandbox Code Playgroud)
和预期的输出:
1593 SSS Sudowoodo? 15 15 …Run Code Online (Sandbox Code Playgroud) 我在多个目录中有多个文件,我需要一个 grep 命令,该命令仅当文件中存在两种模式时才能返回输出。图案类似于AccessToken和Registrationrequest。图案不在同一条线上。AccessToken可以在一行中,Registrationrequest也可以在另一行中。还要在所有目录中的所有文件中递归搜索相同的内容。
试过
grep -r "string1” /directory/file | grep "string 2”
grep -rl 'string 1' | xargs grep 'string2' -l /directory/ file
grep -e string1 -e string2
Run Code Online (Sandbox Code Playgroud)
没有任何效果
有人可以帮忙吗?
我想用这样的文本更改文件
Application[0]=test_app1
Application[0]=test_aap2
Application[0]=test_app3
Application[0]=test_app4
..
Run Code Online (Sandbox Code Playgroud)
有这样的升序数字:
Application[0]=test_app1
Application[1]=test_aap2
Application[2]=test_app3
Application[3]=test_app4
..
Run Code Online (Sandbox Code Playgroud) 只想在 Windows 文件路径中转义空格。我正在尝试这个:
echo "111 1111 "| sed -e "s/[[:space:]]/\\ /g"
Run Code Online (Sandbox Code Playgroud)
只匹配空格但不替换。
command-line sed text-processing windows-subsystem-for-linux
我正在尝试解析一个多行句子:
You have to go tomorrow by
car.
Run Code Online (Sandbox Code Playgroud)
如您所见,有一个新的 line + space 然后是“car”。
我使用了这个正则表达式:
You.have.to.go.tomorrow.by.\n.+
Run Code Online (Sandbox Code Playgroud)
当我将它与regex101一起使用时效果很好,但是当我在 bash 中使用它时,它仅适用于第一句话:
Parser='You.have.to.go.tomorrow.by.\n.+'
Run Code Online (Sandbox Code Playgroud)
结果:
You have to go tomorrow by
Run Code Online (Sandbox Code Playgroud)
我正在使用 bash,我想要完整的句子:
"You have to go tomorrow by car."
Run Code Online (Sandbox Code Playgroud)
我在用:
sed -e 's/<[^>]\+>/ /g' | grep -oP $parser
Run Code Online (Sandbox Code Playgroud)
删除所有 HTML 标签,然后 grep 解析器。
我有一个域列表,如下所示:
a.example.com
b.foo.com
a.b.bar.com
Run Code Online (Sandbox Code Playgroud)
我只希望输出能够获取二级域,而不是其他域,即没有三级或更高级别的域。这就是我从上面的示例列表中寻找的内容:
example.com
foo.com
bar.com
Run Code Online (Sandbox Code Playgroud)
我尝试过使用sed、awk和 ,cut如下所示:
sed
cat domains.txt | sed 's/\.$//g'
cat domains.txt | sed -r 's/^(.*)_/\1\\/; s/.$//g' # this removes the last character for some reason
Run Code Online (Sandbox Code Playgroud)
awk
awk '{ sub(/\.$/, ""); print $NF }' domains.txt
cat domains.txt | awk -F\. '{print $1,$2}' | tr ' ' '.' # won't work since there are 4th level domains
Run Code Online (Sandbox Code Playgroud)
切
cat domains.txt | cut -d '.' -f[field] # won't …Run Code Online (Sandbox Code Playgroud) 我使用此代码来使用 GitHub API 并自动执行一些任务:
curl --silent -H 'Authorization: token github_access_token' 'https://api.github.com/orgs/OrganizationName/repos?per_page=100'
Run Code Online (Sandbox Code Playgroud)
有时我得到这样的回应:
[
]
Run Code Online (Sandbox Code Playgroud)
我想知道响应是否是空数组。
我想过使用jqlikeecho $Response | jq -r ".[]"但我不知道如何从那里继续。
如何在 bash 中找出 JSON 字符串是否为空数组?
text-processing ×10
command-line ×7
sed ×4
scripts ×2
bash ×1
csv ×1
grep ×1
json ×1
kubuntu ×1