我有一个简单的文本文件,名为samples.log。在这个文件中我有几行。假设我一共有10行。我的目的是将文件的前5行替换为同一文件的最后一行。例如:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
变成:
line 6
line 7
line 8
line 9
line 10
换句话说,我只是想删除文件的前5行,然后我想移到最后5行,我正在Linux上工作。做这件事最简单的方法是什么?有命令吗?我正在编写一个C程序,但我认为最好在程序中执行linux命令,而不是在C中执行这个操作,我认为这是相当困难
我正在阅读coreutils源代码来学习linux下的编程。
我发现,在大多数像ls.c、cat.c这样的程序中,它们在前几行调用宏函数initialize_main()。因此,我查看了system.h以找到实现:
/* Redirection and wildcarding when done by the utility itself.
Generally a noop, but used in particular for native VMS. */
#ifndef initialize_main
# define initialize_main(ac, av)
#endif
我不明白
我试着执行以下几行-
sh """
#!/bin/bash
cd ${WORKSPACE}
cat << EOF > build.sh
#!/bin/bash
mkdir wsbuildlinux
cd wsbuildlinux
cmake3 ../../wiresharkbuild_linux
make
EOF
chmod 755 build.sh
# run container and build wire
我有很多csv文件,想读进去。我想跳过开头的行,直到行以实际数据开始。我的文件碰巧以某些字符串开头,比如"OPQ“或"BST”。这些文件看起来像:
"This is a new record.
There are some missing data.
The test condition is 60 degree"
OPQ , 11 , speed , -3 , 20
BST , 20 , speed , 4 , 10
....
前几行变化很大。只想跳过前几行,可能是3行或更多的描述,然后是几行空行。数据从行开始,以"OPQ“或"
我有两个文件: file1和file2。File1有很多行/行和列。File2只有一列,有几行/几行。在file1中可以找到file2中的所有字符串。我想创建一个新文件(file3),
例如,
File1:
Sally ate 083 popcorn
Rick has 241 cars
John won 505 dollars
Bruce knows 121 people
File2:
083
121
所需的file3:
Sally ate 083 popcorn
Bruce knows 121 people
我有一个很大的独立的CSV文件。但是,它缺少一些数据:
1 cat The cat ate the fish.
dog The dog played in the yard.
fish The fish went to the river.
2 eagle The eagle flew in the sky.
The eagle stopped in the mountains.
bear The bear ate the honey.
我需要用出现在前几行中的任何数据填充所有空单元
输入文件包含以下几行:
a
b
c
我希望输出为(n倍):
a
b
c
a
b
c
我试过下面的命令,但它不能维持命令
while read line; do for i in {1..4}; do echo "$line"; done; done < file
但是输出结果是
a
a
b
b
c
c
我在试着运行jvisualvm。奇怪的是,它在90%的时间里都无法工作,并留下了这个错误:
完全错误:
错误的前几行:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fda78e35880, pid=4065, tid=140577382409984
#
# JRE version: 6.0_27-b27
# Java VM: OpenJDK 64-Bit Server VM (20.0-b12 mixed mode linux-amd64