AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1098013

Insideup's questions

Martin Hope
Insideup
Asked: 2021-07-16 09:13:17 +0800 CST

如何恢复主机磁盘空间?使用 Virtual Machine Manager 添加和删除虚拟磁盘时 KVM 内存不足而丢失

  • 0

在使用 KVM 和 Virtual Machine Manager 时,我发现磁盘空间不足,同时执行以下操作:

  1. Virtual Machine Manager,Details view,选择VirtIO Disk 1,右键选择Add Hardware,输入大小。
  2. 运行虚拟机并进行测试。
  3. 关闭虚拟机。
  4. Virtual Machine Manager,Details 视图,选择 VirtIO Disk 2,右键单击并选择 Remove Hardware。
  5. Virtual Machine Manager,Details view,选择VirtIO Disk 1,右键选择Add Hardware,输入不同的大小。
  6. 运行虚拟机并进行测试。
  7. 然后重复,移除第二个虚拟磁盘并添加一个不同大小的新磁盘。

这样做一段时间后,主机报告其空间不足并崩溃。哎呀!也许删除的虚拟硬件也没有被删除?

重新启动,我使用虚拟机管理器删除了虚拟机,主机看起来很开心,但磁盘仍然很满。(而且 Virtual Machine Manager 也没有我所有的其他虚拟机(哎呀!),但该列表稍后重新填充 - 对于任何来到这里的人也有这个问题,希望这对你来说也是如此。此外,virsh list什么也没给,仍然可以,这使它更加可怕)。

如何删除未使用的虚拟磁盘(如果那是占用内存的东西)?

virtualization
  • 1 个回答
  • 406 Views
Martin Hope
Insideup
Asked: 2021-01-12 18:49:18 +0800 CST

awk -v var=$var /var/ 没有按预期工作

  • 0

文件部分:

 <style:style style:name="P15" style:family="paragraph" style:parent-style-name="Table_20_Contents">
      <style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/>
      <style:text-properties style:font-name="open sansregular2" fo:font-size="18pt" fo:font-weight="normal" officeooo:rsid="00300000" officeooo:paragraph-rsid="00100000" style:font-size-asian="18pt" style:font-weight-asian="normal" style:font-size-complex="18pt" style:font-weight-complex="normal"/>
    </style:style>
    <style:style style:name="P16" style:family="paragraph" style:parent-style-name="Table_20_Contents">
      <style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/>
      <style:text-properties fo:color="#000000" style:font-name="open sansregular2" fo:font-size="18pt" officeooo:rsid="00050000" officeooo:paragraph-rsid="000040000" style:font-size-asian="18pt" style:font-size-complex="18pt"/>
    </style:style>
    <style:style style:name="P17" style:family="paragraph" style:parent-style-name="Table_20_Contents">
      <style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/>
      <style:text-properties fo:color="#000000" style:font-name="open sansregular" fo:font-size="18pt" officeooo:rsid="00100002" officeooo:paragraph-rsid="00100002" style:font-size-asian="18pt" style:font-size-complex="18pt"/>
    </style:style>
awk '/\<style:style style:name="P16"/,/style:style\>/' RS='\</style:style\>' file

虽然可能没有正确形成,但会产生预期的结果:

<style:style style:name="P16" style:family="paragraph" style:parent-style-name="Table_20_Contents">
      <style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/>
      <style:text-properties fo:color="#000000" style:font-name="open sansregular2" fo:font-size="18pt" officeooo:rsid="00050000" officeooo:paragraph-rsid="000040000" style:font-size-asian="18pt" style:font-size-complex="18pt"/>

(我想要整个块,包括</style:style>, 但可以按原样使用),但是,

echo $TPNum
"P16"
awk -v TPNum=$TPNum '/\<style:style style:name=TPNum/,/style:style\>/' RS='\</style:style\>' file

除了相同的警告之外,不会产生任何结果:awk: warning: escape sequence `\<' treated as plain `<' awk: warning: escape sequence `\>' treated as plain `>'. 我以前在 awk 中使用过变量,没有任何问题。请问我在这里缺少什么?

command-line
  • 1 个回答
  • 85 Views
Martin Hope
Insideup
Asked: 2020-12-17 05:47:10 +0800 CST

具有特定文件扩展名的 cp 递归

  • 8

我正在尝试复制所有.odt文件,包括子目录中的文件。

cp -r ~/Documents/* ~/copies # works as expected
cp -r ~/Documents/*.odt ~/copies # does not work as expected

第一行将复制所有文件和所有子目录,但第二行将仅复制子目录中的.odt文件~/Documents,不复制子目录中的文件。

command-line bash cp
  • 2 个回答
  • 3354 Views
Martin Hope
Insideup
Asked: 2020-11-28 15:19:14 +0800 CST

如何使用 awk 编辑由变量设置的特定行(awk NR、-i inplace 和 -v var)

  • 0

如果文件是:

this is line one
this is line two
this is line three

我想做类似的事情:

awk -i inplace -v line_number=$line_number 'NR == line_number {print $1}' file 

让我们说line_number=1。那么期望的结果是:

this
this is line two
this is line three

但相反,该文件被第 1 行的编辑版本完全替换,导致:

this

达到预期结果的正确方法是什么?

command-line bash awk
  • 1 个回答
  • 117 Views
Martin Hope
Insideup
Asked: 2020-11-13 07:27:44 +0800 CST

在每一行包装特定字段

  • 0

文件:

DocumentNameA varying number of words symbols etc
DocumentName2 varying number of words symbols etc
AnotherDocumentName varying number of words symbols etc

我想做类似的事情

sed -i 's/$1/"<opentag>"$1"</closetag>"/' file

将文件更改为

<opentag>DocumentNameA</closetag> varying number of words symbols etc
<opentag>DocumentName2</closetag> varying number of words symbols etc
<opentag>AnotherDocumentName</closetag> varying number of words symbols etc

似乎必须有一个简单的方法来做到这一点,但我还没有找到它

command-line bash sed
  • 2 个回答
  • 22 Views
Martin Hope
Insideup
Asked: 2020-10-31 12:38:06 +0800 CST

如何在匹配模式的行上替换不同数量的字符串

  • 0

文件 1

<filename1.txt> stringA string1
<filename2.txt> stringA string2
<filename2.txt> stringB string3

文件2

<filename1.txt>      words and symbols < $ stringA words and symbols 9 
<filename2.txt>      more words and symbols % @ stringA words and symbols stringB

File2 已转换

<filename1.txt>      words and symbols < $ string1 words and symbols 9
<filename2.txt>      more words and symbols % @ string2 words and symbols string3

我的方法是遍历 File1 的行来设置变量。所以对于第 1 行,vars 设置为:

filenamevar = <filename1.txt>
string_old_var = stringA 
string_new_var = string1 

然后 grep 匹配 filenamevar 和 string_old_var 的行作为 sed 的输入。这就是我需要帮助的地方(除非您认为有更好的方法)。

到目前为止最接近的是

grep -e "$filenamevar.*$string_old_var" File2.txt | sed s/$string_old_var/$string_new_var/ >> File2Transformed.txt

除了第二行输出两次之外,它的工作原理:

<filename1.txt>      words and symbols < $ string1 words and symbols 9 
<filename2.txt>      more words and symbols % @ string2 words and symbols stringB
<filename2.txt>      more words and symbols % @ stringA words and symbols string3

我也试过

grep -e "$filenamevar.*$string_old_var" File2 | sed s/$string_old_var/$string_new_var/

和

sed -i s/$string_old_var/$string_new_var/ $(grep -e "$filenamevar.*$string_old_var" File2)

但两者都不会产生预期的结果。

这是我正在使用的循环

Numlines=$(grep "" -c File1.txt) 
for (( line=1; line<=$Numlines; line++ )) ; do 
 filenamevar=$(awk -v line=$line 'NR == line {print $1}' File1.txt) 
 string_old_var=$(awk -v line=$line 'NR == line {print $2}' File1.txt)
 string_new_var=$(awk -v line=$line 'NR == line {print $3}' File1.txt)
 # insert proper sed grep code to test here
done
scripts command-line bash sed grep
  • 1 个回答
  • 85 Views
Martin Hope
Insideup
Asked: 2020-10-26 09:34:33 +0800 CST

如果特定行包含子字符串,则输出其他子字符串

  • 0

我想在文件的每一行上查找一个字符串,如果它存在,则返回一个不同的特定字符串。

在发布解决方案后,此帖子已被编辑,以帮助更好地说明问题(因此一些较早的回复不再适用)

我有这个代码:

Numlines=$(grep "" -c File.txt)
for (( line=1; line<=$Numlines; line++ )) ; do 
awk -v line="$line" 'NR==line ...???

我正在寻找的字符串是style-name="T. 如果该字符串在 for 循环中的一行中,则返回T. 中的行File.txt可能包含类似的字符串style-name="T2",在这种情况下,我只想返回2. 该字符串不在 中的每一行的相同位置File.txt,所以我认为我不能在 中使用字段名称awk。

IIRC,"/style-name\=\"T/"应该提供匹配,但如果我在我的代码中使用它,它要么给我一个错误,要么什么都不返回。也许脚本会检查它是否可以产生匹配,如果可以,使用第二行代码来获取字符串,尽管我认为awk可以通过单行代码完成它,一旦前驱代码被计算出来出去。

这是一个示例File.txt:

<TEST1>     <text:p text:style-name="P4">Hello<text:span text:style-name="T2">world</text:span></text:p>
<tyi.ggg>     <text:p text:style-name="P9">Hi<text:span text:style-name="T16">there</text:span></text:p>
<TEST2>     <text:p text:style-name="P540">0 <text:s/>oooh yeah<text:s text:c="2"/>kool-aid<text:s text:c="12"/>0:00</text:p>

第一行(第一次通过for循环)的输出应该是 2。第二行(第二次通过for循环)的输出应该是 16。第三行的输出应该是什么。

command-line text-processing
  • 2 个回答
  • 144 Views
Martin Hope
Insideup
Asked: 2020-10-25 12:49:36 +0800 CST

awk NR 变量未按预期工作,在请求第一个字段时获取整行

  • 0
echo cat:
cat Records.txt
echo ""
echo Using a digit for the second record:
record_id=$(awk 'NR==2{print $1; exit}' Records.txt)
echo $record_id
echo ""
a=2
echo a is set to $a
echo ""
echo Using a variable and single quotes:
record_id=$(awk 'NR==$a{print $1; exit}' Records.txt)
echo $record_id
echo Using a variable and double quotes:
record_id=$(awk "NR==$a{print $1; exit}" Records.txt)
echo $record_id

输出

cat:
Apples 1000 happy worms
Carrots 10 happy bunnies

Using a digit for the second record:
Carrots

a is set to 2

Using a variable and single quotes:

Using a variable and double quotes:
Carrots 10 happy bunnies

我知道使用变量需要双引号,但为什么它不再仅限于第一个字段的输出?我只想要胡萝卜这个词。

scripts bash awk
  • 2 个回答
  • 616 Views
Martin Hope
Insideup
Asked: 2020-10-24 06:49:49 +0800 CST

如何为文件的每一行添加交互值?

  • 0
Numlines=$(grep "" -c file.txt) # This works
for line in $( seq 1 $Numlines) # for each line 
do
sed "s/$/ Line${i}/" file.txt # not right
done

文件.txt:

this is the first line
this is the second line
this is the third line

期望的输出

this is the first line  Line1
this is the second line  Line2
this is the third line  Line3

相反,我得到:

this is the first line Line1
this is the second line Line1
this is the third line Line1
this is the first line Line2
this is the second line Line2
this is the third line Line2
this is the first line Line3
this is the second line Line3
this is the third line Line3
command-line bash sed
  • 1 个回答
  • 43 Views
Martin Hope
Insideup
Asked: 2020-10-08 07:46:54 +0800 CST

带有 RS 的 AWK 与模式不匹配(再次询问,因为我不小心将其标记为已解决。这次更好的解释。)

  • 0

我有一个 odt 文件,文本行之间有空行。我想搜索一个术语并输出与该术语匹配的整组文本。我的做法是说odt文件中的空行是记录分隔符。Odt 文件是 zip 档案,其文本包含在 content.xml 中。解压缩 odt 文件后,我使用 xmllint --format content.xml 插入换行符(如下所示),“空白”行实际上是 > 和 < 之间没有文本的行。所以我想将 RS 设置为在 > 和 < 之间没有文本的任何此类行。如果格式化后的 content.xml 文件如下:

<long line of alphanumerics, slashes, single and double quotes><more or the same><and many more>
      <office:text>
      <text:sequence-decls>
        <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
        <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
        <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
        <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
        <text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
      </text:sequence-decls>
      <text:p text:style-name="P1">This is the first line</text:p>
      <text:p text:style-name="P1"/>
      <text:p text:style-name="P1">This is the third line</text:p>
      <text:p text:style-name="P1">and this is some more text that is to be included</text:p>
      <text:p text:style-name="P1"/>
      <text:p text:style-name="P1">This is the sixth. I want it included,</text:p>
      <text:p text:style-name="P1">with this line</text:p>
      <text:p text:style-name="P1">and this one</text:p>
    </office:text>

和代码是

$ awk '/line/' RS='\n[ \t]*<[^>]*>\n' file.xml

整个文件被输出。但我只想要:

      <text:p text:style-name="P1">This is the first line</text:p>
      <text:p text:style-name="P1">This is the third line</text:p>
      <text:p text:style-name="P1">and this is some more text that is to be included</text:p>
      <text:p text:style-name="P1">This is the sixth. I want it included,</text:p>
      <text:p text:style-name="P1">with this line</text:p>
      <text:p text:style-name="P1">and this one</text:p>
command-line bash awk
  • 2 个回答
  • 151 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve