每次找到匹配项时,我都想打印上一行。我知道grep -A
和-B
选项。但是我的 Solaris 5.10 机器不支持这些选项。
我想要只使用sed
.
Foo.txt
:
Name is : sara
age is : 10
Name is : john
age is : 20
Name is : Ron
age is : 10
Name is : peggy
age is : 30
Run Code Online (Sandbox Code Playgroud)
Out.txt
:
Name is : sara
Name is : Ron
Run Code Online (Sandbox Code Playgroud)
我试图匹配的模式是age is : 10
.
我的环境,Solaris 5.10。
我想在输入文件的每一行后插入 5 个空行。
foo.txt
:
line 1
line 2
line 3
Run Code Online (Sandbox Code Playgroud)
out.txt
:
line 1
line 2
line 3
...
Run Code Online (Sandbox Code Playgroud)
Solaris 5.10nawk
或sed
.
输入.txt:
8B0C
remove
8B0D
remove
8B0E
remove
8B0F
8B10
remove
8B14
remove
8B15
remove
8B16
remove
8B17
remove
8AC0
8AC1
remove
8AC2
remove
8AC3
remove
8AE4
8AE5
8AE6
remove
Run Code Online (Sandbox Code Playgroud)
期望的输出:
8B0F
8AC0
8AE4
8AE5
Run Code Online (Sandbox Code Playgroud)
如果该行或下一行不包含“删除”,我想打印一行。我使用的是solaris 5.10,KSH。
我正在尝试从 servicenow 网站获取 html 数据。它使用框架,我想使用 wget 提取框架源。我无法找到完成这项工作的选项/标志。我只能提取页面源,而不能提取框架源。
wget -q https://company.service-now.com/task.do?sysparm_query=number=TASK0299719
Run Code Online (Sandbox Code Playgroud)
您好,我希望能够使用 AWK 或 SED 来编辑姓名列表。
输入列表文件示例:
john
paul
rose
lily
Run Code Online (Sandbox Code Playgroud)
期望的输出:
I am john of earth;
I am paul of earth;
I am rose of earth;
I am lily of earth;
Run Code Online (Sandbox Code Playgroud)
我也想要末尾的分号。我不想使用 for 循环的 shell 脚本。
file1.txt
:
hi
wonderful
amazing
sorry
superman
superhumanwith
loss
Run Code Online (Sandbox Code Playgroud)
file2.txt
:
1
2
3
4
5
6
7
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 paste -d" " file1.txt file2.txt > actualout.txt 进行组合时
actualout.txt
:
hi 1
wonderful 2
amazing 3
sorry 4
superman 5
superhumanwith 6
loss 7
Run Code Online (Sandbox Code Playgroud)
但我希望我的输出看起来像这样
OUT.txt
:
hi 1
wonderful 2
amazing 3
sorry 4
superman 5
superhumanwith 6
loss 7
Run Code Online (Sandbox Code Playgroud)
哪个命令可用于组合 2 个文件,使其看起来像所需的输出?Solaris 5.10 ksh nawk、sed、粘贴
我有一个带有以下几行的小脚本
echo mom,dad |awk -F, '{print $1,$2}' | while read VAR1 VAR2
do
for i in VAR1 VAR2
do
eval X=\$$i
echo $X
done
done
Run Code Online (Sandbox Code Playgroud)
输出:
mom
dad
Run Code Online (Sandbox Code Playgroud)
这条线在做什么eval X=\$$i
?
我理解其余的行,但我不理解这个 for 循环与 eval 的迭代。有人可以解释一下吗?我正在将 Solaris 5.10 与 Korn Shell 一起使用。
Sample Input:
title role subject
name-JOHN student math
school state NY
county street Phone
name-TOM student math
school state TX
county street Phone
name-LILLY student math
school state LA
county street Phone
name-ROSY student math
school state WA
county street Phone
garbage line 1
garbage line 2
Run Code Online (Sandbox Code Playgroud)
Desired Output
JOHN NY
TOM TX
LILLY LA
ROSY WA
Run Code Online (Sandbox Code Playgroud)
底部 2 条垃圾线必须消失。我想使用 AWk 还是 SED?
我正在运行 Sun 操作系统。
输入.txt:
john_Apple01_xyz_1
john_Fruit_Apple01_abc_c1
john_Apple21_trs_1
john_Fruit_Apple21_efg_1
john_Fruit_Apple21_tefg_1
Run Code Online (Sandbox Code Playgroud)
期望的输出:
Apple01_xyz_1
Apple01_abc_c1
Apple21_trs_1
Apple21_efg_1
Apple21_tefg_1
Run Code Online (Sandbox Code Playgroud)
每次在行中找到苹果时,如何使用 nawk 或 sed 来剪切前导部分?
我在 Solaris 10 中使用 KSH。
我有一个 4 行输入文件,我需要修改该文件以组合备用行。我想就地执行操作。
INPUT:
Tom
Nathan
Jack
Polo
Desired Output:
Tom Jack
Nathan Polo
Run Code Online (Sandbox Code Playgroud)
一种方法是收集奇数行并翻转它们并剪切偶数行并组合两个文件以获得最终输出。但我正在寻找一个更简单的解决方案。
我有一系列存储在其中的模式foo.txt
,我想遍历这些模式并查看 file 中的哪些匹配行bar.txt
。
while read PWW
do
cat user/dump/bar.txt | awk '/${PWW}/{print $2}' >> user/dump/out.txt
done < user/dump/foo.txt
Run Code Online (Sandbox Code Playgroud)
foo.txt
:
2100001b32
2100001b38
3100001b35
4100001b28
5100001b46
6100001b56
Run Code Online (Sandbox Code Playgroud)
bar.txt
:
2100001b32 good
2100001b38 bad
3100001b35 okay
4100001b28 large
5100001b46 good
6100001b56 bad
Run Code Online (Sandbox Code Playgroud)
想要的out.txt
:
good
bad
okay
large
good
bad
Run Code Online (Sandbox Code Playgroud)
我无法搜索foo.txt
. while 循环运行并给我空输出。我想awk
是${PWW}
从foo.txt
.
我怎样才能让它工作?我的环境是 Solaris 5.10,使用 Korn shell,基本awk
(旧awk
)。
输入示例:
apple_ig
rabbit_cat_ig
dog_ig
bird_duck_ig
orange_ig
goat_ig
Run Code Online (Sandbox Code Playgroud)
预期输出:
apple_ig
dog_ig
orange_ig
goat_ig
Run Code Online (Sandbox Code Playgroud)
我需要忽略整个字符串中多次包含下划线 _ 的所有数据。
bash、ksh、sed、grep、awk
我正在尝试创建一个文件,看起来vi
编辑器$
在每行的末尾添加了一个。我不知道是什么导致了这种情况或如何防止vi
这样做。
vi file.txt
12345
abcde
cat -v -e file.txt
12345$
abcde$
wc file.txt
2 2 12
Run Code Online (Sandbox Code Playgroud)
最后我不想要那些$
符号;他们破坏了我的自动化文件,这取决于字符数。为什么字数会显示 12 个字符,而实际上每行有 5 个字符?
VIM 版本 7.4.629