使用regexp字符串,如何删除包含匹配的第一行之前的所有行?例如,我如何才能改变这一点:
lost
load
linux
loan
linux
这方面:
linux
loan
linux
我试过:
echo "lost
load
linux
loan
linux" | sed -e 's/.*^li.*$//g'
但是它返回这个,而不是改变任何东西:
lost
load
linux
loan
linux
我想让它工作,这样当没有匹配的时候,它就不会输出任何东西。
我正在尝试写一个命令,它将获得每个平台的最后一个数字,并将它们相加,然后将该数字保存为变量。例如,对于下面随机文件中的"AIX“,我希望能够提取1和115,并将116保存为变量。然后,对于"Linx“,我想保存2、16、18、96和1,并将和保存为另一个变量。
cat randomfile.txt:
AIX,5.5.3-0,1
AIX,6.2.1-0,115
Linux x86-64,6.4.0-0,2
Linux x86-64,6.4.0-1,16
Linux x86-64,7.1.2-0,18
Linux86,6.1.3-4,96
Linux86,6.2.5-0,1
我能
输入:
START
OS:: UNIX
Release: xxx
Version: xxx
END
Description about UNIX
<Multiline>
START
OS:: LINUX
Release: xxx
Version: xxx
END
Description about LINUX
<Multiline>
START
OS:: Windows
Release: xxx
Version: xxx
END
Description about Windows
<Multiline>
在这里,我试图获得所有的信息之间的开始和结
我有很多文本文件,我想在linux中创建一个bash脚本,在每一行文件中打印文件名。例如,我有lenovo.txt文件,我希望文件中的每一行都以lenovo.txt开头。
我试着为这个做一个" for“,但没有起作用。
for i in *.txt
do
awk '{print '$i' $0}' /var/SambaShare/$i > /var/SambaShare/new_$i
done
谢谢!
我正在尝试替换文件中出现的第一个字符串。例如,试图用linux取代第一个foo
sample.txt
Hi foo bar
This is again foo bar.
命令:sed '0,/foo/s//linux/' sample.txt
上述命令的实际输出(基本不变)
Hi foo bar
This is again foo bar.
我的预期产出如下
Hi linux bar
This is again foo bar.
这里有人能帮忙吗?
我需要一个与any character(s) followed by foo. or bar. followed by anything followed by is.a.server followed by anything匹配的正则表达式。
例如:
"foo.lnx station is.a.server" # match this
"my bar.unx node is.a.server.and.client" # match this
"baz station is.a.server" # do NOT not match this
我有一个ascii文件,内容如下:
START
this is my home
this is my pc
START
this is my linux
this is my awk
this is nice
START
this is a single line
START
this is my work
this is the end
this line has to be read
START
...
...
START
.
.
.
.
我希望读取开始行和空行之间的行,并以分隔格式打印输出。产出应采用以下格式:
this is my home;this is my pc
thi
我正在尝试使用AWK在特定分隔符上拆分文件。awk代码如下所示:
awk '/SEPARATOR/{n++}{print > "part" n ".txt" }' in.txt
这段代码在我的Linux系统上运行得很好。但是,当在Mac OS X上运行完全相同的代码时,我得到以下错误:
awk: syntax error at source line 1
context is
/SEPARATOR/{n++}{print > "part" >>> n <<< "
我在linux设备驱动程序一书中读到了这行脚本。是干什么的呢?
major=$(awk "\\$2= =\"$module\" {print \\$1}" /proc/devices)
在上下文中:
#!/bin/sh
module="scull"
device="scull"
mode="664"
# invoke insmod with all arguments we got
# and use a pathname, as newer modutils don't look in
假设在linux中有一个文件,它的行用空格分隔。
例如:
This is linux file
This is linux text
This is linux file 1
This is linux file 3
现在我只想打印那些在文件行中有第5列的行。在本例中,我的输出应该是第3行和第4行(其中1和3作为第5列)
做这件事最好的方法是什么?