我是编程新手!!
任何人都可以帮助删除:时间戳中的第一个位置::29.06.2019 23:03:17
目前我正在尝试使用 awk/cut 命令来做到这一点,如下所示:
TDS="$(grep 'Logfile started' process.log | awk '{print $3,$4}' | cut -d: -f2)"
echo "$TDS"
29.06.2019 23
Run Code Online (Sandbox Code Playgroud)
输出不是我想要的!我想将其打印为29.06.2019 23:03:17.
我正在阅读这篇文章。那里有一个声明:
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 25 -i :0.0 -sameq -f mpeg -ar 48000 -s wvga -y sample.mp4
Run Code Online (Sandbox Code Playgroud)
当我运行命令时,出现以下部分的错误:
xwininfo -root | grep 'geometry' | awk '{print $2;}'
Run Code Online (Sandbox Code Playgroud)
原因是当你在我的电脑上使用这个命令时,它输出:
1360x768+0+0
Run Code Online (Sandbox Code Playgroud)
如何删除屏幕分辨率输出的最后一部分1360x768而不是1360x768+0+0?
我正在编写的 awk 脚本中有几个命令:
print "Here are some players and their numbers, sorted by last name"
if(sum[x] > 500) {print x, $2}
Run Code Online (Sandbox Code Playgroud)
哪些输出:
Here are some players and their numbers, sorted by last name
Lebron James 23
Kevin Durant 35
Kobe Bryant 24
Blake Griffin 32
Dikembe Mutumbo 55
Run Code Online (Sandbox Code Playgroud)
如何使用awk 脚本中的sort命令仅对玩家及其号码进行排序?
File1.txt
item1 carA
item2 carB
item3 carC
item4 platD
item5 carE
Run Code Online (Sandbox Code Playgroud)
File2.txt
carA platA
carB platB
carC platC
carE platE
Run Code Online (Sandbox Code Playgroud)
想要的输出:
item1 platA
item2 platB
item3 platC
item4 platD
item5 platE
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我似乎无法使用 awk 命令来获取第二列数据。
重击代码:
filter_data=$(awk "{if(/$filter:/) print $2}" < scanresults_temp.txt)
printf "$filter_data \n"
Run Code Online (Sandbox Code Playgroud)
$filter 变量是传递到 shell 脚本的 Download 或 Upload 的值。所以 awk 使用术语下载或上传来搜索正确的行。
文件内容为:
Testing download speed................................................................................
Download: 51.13 Mbit/s
Testing upload speed................................................................................................
Upload: 57.38 Mbit/s
Run Code Online (Sandbox Code Playgroud)
我试图只得到数字而不是其他任何东西,例如,51.13和57.38.
echo '((3+(2^3)) * 34^2 / 9)-75.89' | awk "BEGIN{ print $(cat) }"
Run Code Online (Sandbox Code Playgroud)
上述语法适用于计算结果“1337”。
echo '((3+(2^3)) * 34^2 / 9)-75.89' | awk "BEGIN{ print $* }"
Run Code Online (Sandbox Code Playgroud)
但是上面的语法不起作用,尽管没有错误。
请各位指教。
我只想通过 awk 打印输入中除最后三行之外的所有行。请注意,我的文件包含 n 行。
例如,
file.txt 包含,
foo
bar
foobar
barfoo
last
line
Run Code Online (Sandbox Code Playgroud)
我希望输出是,
foo
bar
foobar
Run Code Online (Sandbox Code Playgroud)
我知道通过tac和sed或tac和的组合是可能的awk
$ tac file | sed '1,3d' | tac
foo
bar
foobar
$ tac file | awk 'NR==1{next}NR==2{next}NR==3{next}1' | tac
foo
bar
foobar
Run Code Online (Sandbox Code Playgroud)
但我只希望通过 awk 输出。
该函数awk '!seen[$0]++'打印输入管道中的新出现。
但是,我无法在之后添加管道。例如
my_function_with_ouput | awk '!seen[$0]++' | while read j
do
echo $j
done
Run Code Online (Sandbox Code Playgroud)
不产生任何输出。
在我的文件中mytxt:
field1 field2
------ -------
this are numbers 12345
this letters abc def ghi
Run Code Online (Sandbox Code Playgroud)
假设我想将第一个字段存储在数组中:
i=0
while read line; do
field_one[$i]=$(echo $line | awk '{print $1}')
echo ${field_one[i]}
((i++))
done < mytxt
Run Code Online (Sandbox Code Playgroud)
这会给我this两次输出。
关于如何将它们存储在数组中并获得输出的任何想法:
this are numbers
this letters
Run Code Online (Sandbox Code Playgroud)
我曾尝试更改分隔符、压缩空格和使用sed,但我被卡住了。任何提示将不胜感激。
我的最终目标是将两个字段存储在一个数组中。
只是一个简单的问题。
为什么这个 bash 命令在 Ubuntu 服务器上可以正常工作并找出 ISBN 代码,但在我的 Ubuntu 桌面上却不起作用?两个系统都是 22.04 LTS。
echo "ISBN 5-02-013850-9" | awk '/ISBN [0-9]{1}-[0-9]{2}-[0-9]{6}-[Xx0-9]{1}/ {print $0}'
Run Code Online (Sandbox Code Playgroud)
提前致谢。