我需要一些帮助来解析Linux中的字符串.
我有一个字符串:
[INFO] Total time: 2 minutes 8 seconds
Run Code Online (Sandbox Code Playgroud)
并且只想获得
2 minutes 8 seconds
Run Code Online (Sandbox Code Playgroud) 输入文件:
$ cat t.txt
id1;value1_1
id1;value1_2
id2;value2_1
id3;value3_1
id4;value4_1
id4;value4_2
id5;value5_1
Run Code Online (Sandbox Code Playgroud)
结果将是:
id1;value1_1;id1;value1_2
id3;value3_1
id4;value4_1;id4;value4_2
id5;value5_1
Run Code Online (Sandbox Code Playgroud)
使用sed或awk.请提出你的意见.
我sed用来查找和替换文件中的一些项目,如下所示:
sed -i "s/$a/$b/g" ./file.txt
Run Code Online (Sandbox Code Playgroud)
我需要限制此查找并替换为仅当匹配文本位于方括号之间时,例如:
The sheep lived in the barn.
One day, [the sheep ate some] grass.
The [sheep] found a nice place to sleep under the tree.
Afterwards, [the sheep ate apples under] the tree [near the barn].
The sheep [enjoyed the theme] of the movie.
Run Code Online (Sandbox Code Playgroud)
假设$a设置为"the"并$b设置为"B",输出将如下所示:
The sheep lived in the barn.
One day, [B sheep ate some] grass.
The [sheep] found a nice place to sleep under the tree. …Run Code Online (Sandbox Code Playgroud) 您好我想从变量中删除':' s.
我做了以下程序但是没有用
$s="2:2:2:2:2";
$v=$(sed 's/://g' <<< $s);
print $v;
Run Code Online (Sandbox Code Playgroud)
任何解决方案谢谢
嗨我有2个文件如下,我需要脚本来比较那些并找到匹配.我怎样才能做到这一点?
file1 as a.txt:
Anirban
Ball
Cat
Dog
cow
Run Code Online (Sandbox Code Playgroud)
file2为b.txt:
I am Anirban
I am Ball
I am Cat_cat
I am Dog
I am cow
I am horse
Run Code Online (Sandbox Code Playgroud)
我想要这样的输出:
I am Anirban
I am Ball
I am Dog
I am cow
Run Code Online (Sandbox Code Playgroud)
我尝试过grep -f b a,它没有给出完全匹配.
我正在寻找一个perl/awk/sed命令来自动增加第7列中的数字.文件knownfile.txt中的示例行:
该文件具有格式和7列.
today is a great day and it
is also an amazing day tomorrow now
blahblah foo today build number is 5928
Run Code Online (Sandbox Code Playgroud)
我要保留所有格式,只需更换5928与5929和保存文件
我试过了:
awk '/blahblah/{ $7++; print $0 }' filename > tmp && mv tmp filename
Run Code Online (Sandbox Code Playgroud)
它增加了数字,我认为它保留了格式,但它只将编辑的行打印到文件中.
我希望每次在我的文件中都有包含模式"黄色"的行,它会删除此行和前面的4行.
例如,我的文件:
orange
green
grey
black
blue
yellow
red
green
grey
white
black
yellow
blue
Run Code Online (Sandbox Code Playgroud)
输出文件将是:
orange
red
blue
Run Code Online (Sandbox Code Playgroud)
非常感谢.如果可能的话,使用unix标准命令,如awk,sed,cut,grep,perl脚本,php脚本,python脚本...(我的条目文件非常大,几乎是2Gb,2500万行)
如何在不使用subprocess命令的情况下将以下内容转换为python
cat $MYDIR/* |grep ABCD |grep zip |grep -v idx |awk -F'/' '{print $3}' |awk -F"_" '{print $2}' |awk -F"." '{print $1}' |sed 's/\$[A-Z]//g' | sort|uniq |egrep -v "^ABCD_G9" |egrep -v ABCD_00 |egrep -v "^ABCD_0[1-8]" > $DATADIR/ABCDDataFile
Run Code Online (Sandbox Code Playgroud) 嗨我有一个文件名test.txt
(standard input):8: <property name="ProcedureName" value="abc"/>
(standard input):7: <property name="PackageName" value="123abc"/>
(standard input):8: <property name="ProcedureName" value="bac"/>
(standard input):7: <property name="PackageName" value="bac123"/>
(standard input):8: <property name="ProcedureName" value="cde"/>
(standard input):7: <property name="PackageName" value="cd123"/>
(standard input):8: <property name="ProcedureName" value="b4u"/>
(standard input):7: <property name="PackageName" value="b4u234"/>
Run Code Online (Sandbox Code Playgroud)
我必须以下面的格式从此文件中仅grep packagename和procdeurename的值:进入o/p文件
abc/123abc
bac/bac123
cde/cd123
b4u/b4u234
Run Code Online (Sandbox Code Playgroud)
尝试削减和awk但无法得到
我在Linux OS中有一个包含一些随机数的文件:
1
22
333
4444
55555
666666
7777777
88888888
Run Code Online (Sandbox Code Playgroud)
现在,我有两个条件:1.从每个条目中删除最后3位数字并/在休息之间放置.2.对于数字<= 3,只需添加/替换/符号.
命令我正在尝试满足第一个要求的是:
sed -e 's|\(.\)|\1/|g;s|\(.*\)/\(.\/\)\{3\}|\1|g'
Run Code Online (Sandbox Code Playgroud)
需要的是:
/
/
/
4
5/5
6/6/6
7/7/7/7
8/8/8/8/8
Run Code Online (Sandbox Code Playgroud)
请帮忙.