我是社区的新手,这是我的第一个问题,我希望我做对了。
我的问题:我正在学习一些网络和分析,并且有很长的 MAC 地址列表,我想使用命令行将它们放在同一个句子中,但我不知道如何。
示例: MAC 地址:
xx:xx:xx:xx:xx:xx:xx:xx
yy:yy:yy:yy:yy:yy:yy:yy
zz:zz:zz:zz:zz:zz:zz:zz
Run Code Online (Sandbox Code Playgroud)
我需要的输出:
The mac address xx:xx:xx:xx:xx:xx:xx:xx is not found - but...
The mac address yy:yy:yy:yy:yy:yy:yy:yy is not found - but...
The mac address zz:zz:zz:zz:zz:zz:zz:zz is not found - but...
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我希望你有时间帮助和原谅我的无知,我还在学习,如果我没有花一些时间搜索,我不会问。我看到人们使用 sed、awk 和 perl,但我不明白整个 linux 世界对我来说都是新的。请向我提供有关命令的一些解释,以便我下次学习如何自己做。
我有一个dash7/包含多个文本文件的目录,我想D PRINT从所有这些文件中删除包含字符串的所有行。
我怎样才能从命令行轻松地做到这一点?
我有一个 1 GB 的文件,想将其转换为某种格式。该文件包含以下 URL:
google.com
trafficinviter.com
example.com
Run Code Online (Sandbox Code Playgroud)
我想以这种格式转换完整的内容:
"http://google.com","http://trafficinviter.com","http://example.com"
Run Code Online (Sandbox Code Playgroud)
使用 Ubuntu。这正是 PHP 数组的格式。所以我想知道如何转换为这种格式并保存到另一个文件。
我的输入文件是这样的:
IDno="1"
Name=Jack
Type=Student
IDno="2"
Name=Jill
Type=Teacher
Run Code Online (Sandbox Code Playgroud)
仅当类型为学生时,我才使用 sed 提取所有 IDno 和类型。
sed -e '/IDno=/b' -e '/Type=Student/b' d
Run Code Online (Sandbox Code Playgroud)
这让我得到了所有类型为 student 但不是 IDnos 的行。
我想得到
IDno="1"
Type=Student
IDno="2"
Run Code Online (Sandbox Code Playgroud)
但我得到
Type=Student
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我已经编写了这段代码,但我面临着下面提到的问题。
我的代码是:
paste 1.txt 2.txt|
awk ' { FS = "\t " } ; NR == 1 { n = NF/2 }
{for(i=1;i<=n;i++)
if($i!=$(i+n))
{c = c s i; s = "," }
if(c)
{print "Line No. " NR-1 " COLUMN NO " c;
c = "" ; s = "" } } '
Run Code Online (Sandbox Code Playgroud)
预期输出:
Line No. 2 COLUMN NO 2,3
Line No. 4 COLUMN NO 1,2,3,4
Line No. 6 COLUMN NO 2,3,4,5
Line No. 7 COLUMN NO 1,2,3,4,5
Run Code Online (Sandbox Code Playgroud)
正在生成的输出: …
如何提取第一列(“”中的第一列)
"xxxxx1" {685a}
"xx2" {bcdd}
"xx3 gsdd" {29a6ff}
"sdsdf xxx" {243b9}
"sdfsdf ccc dd" {c28f2f}
"dsdsf sfsdf" {216e}
"sdfsdfsd" {48530}
"sdfsdff" {9d2afa0n}
"sdfsdfdff sdfs" {d8681a}
"sdfsdsds sdfsdf d" {5b9b8}
"sdfsdfs sdf sdfsdf" {68e08a}
"sdfsdfsdf sdf" {107fa0}
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
"xxxxx1"
"xx2"
"xx3 gsdd"
"sdsdf xxx"
"sdfsdf ccc dd"
"dsdsf sfsdf"
"sdfsdfsd"
"sdfsdff"
"sdfsdfdff sdfs"
"sdfsdsds sdfsdf d"
"sdfsdfs sdf sdfsdf"
"sdfsdfsdf sdf"
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我有一个大文件 input.dat,如下所示。
kpoint1 : 0.0000 0.0000 0.0000
band No. band energies occupation
1 -52.8287 2.00000
2 -52.7981 2.00000
3 -52.7981 2.00000
kpoint2 : 0.0000 0.0000 0.0000
band No. band energies occupation
1 -52.8287 2.00000
2 -52.7981 2.00000
3 -52.7981 2.00000
Run Code Online (Sandbox Code Playgroud)
我需要将文件拆分为 2 个较小的文件,如下所示
kpoint1.dat:
kpoint1 : 0.0000 0.0000 0.0000
band No. band energies occupation
1 -52.8287 2.00000
2 -52.7981 2.00000
3 -52.7981 2.00000
Run Code Online (Sandbox Code Playgroud)
和kpoint2.dat:
kpoint1 : 0.0000 0.0000 0.0000
band No. band energies occupation
1 -52.8287 2.00000 …Run Code Online (Sandbox Code Playgroud) 我们如何使用 shell 命令将道尔顿值转换为千道尔顿?我有值的列表道尔顿。一千道尔顿有 1000 道尔顿,因此需要将每个值除以一千。
样本数据:
12345.09
236575.665
18865.41
45678.87
Run Code Online (Sandbox Code Playgroud)
期望的输出:
12.34509
236.575665
18.86541
45.67887
Run Code Online (Sandbox Code Playgroud) 我尝试将文本文件中的某些文本替换为 ,sed但不知道如何使用多个文件进行替换。
我用:
sed -i -- 's/SOME_TEXT/SOME_TEXT_TO_REPLACE/g /path/to/file/target_text_file
Run Code Online (Sandbox Code Playgroud)
在我使用多个文件之前,我使用以下命令在文本文件中打印了目标文本文件的路径:
find /path/to/files/ -name "target_text_file" > /home/user/Desktop/target_files_list.txt
Run Code Online (Sandbox Code Playgroud)
现在我想sed按照target_files_list.txt.
我在文本文件中有一个数字,例如:
int_width: 5230
Run Code Online (Sandbox Code Playgroud)
我想将此数字 (5230) 设置为csh. 什么是正确的形式?(grep 在设置前工作)
set WIDTH = "$(grep int_width *.txt | sed 's/[^0-9]*//g')"
Run Code Online (Sandbox Code Playgroud)