相关疑难解决方法(0)

Linux - Bash将String重定向到文件

我写了一个简单的脚本,它正在读取文件内容并在该文件中增加一个数字,然后我使用awk保持更改,当我尝试使用'>'重定向新的String时,整个字符串被重定向到一个线和不像原来的是4行.

#!/bin/bash -x

# This script is for Incrementing build numbers

path=/home/RND/abrodov
file=tst.txt
tst=`cat $path/$file`
printf "this is the content of the file before incrementing: \n $tst"
newexpr=`awk '/^Build Number/{$4=$4+1;}1' /home/RND/abrodov/tst.txt`
printf "\n the new content \n $newexpr"
echo $newexpr > $path/$file
Run Code Online (Sandbox Code Playgroud)

这是运行脚本之前的原始文件:

Major Release Number = 4
Minor Release Number = 1
Service Pack Release Number = 2
Build Number = 22
Run Code Online (Sandbox Code Playgroud)

这是我使用脚本后的内容:

Major Release Number = 4 Minor Release Number = 1 Service Pack Release Number = 2 …
Run Code Online (Sandbox Code Playgroud)

linux bash shell awk sed

8
推荐指数
1
解决办法
7935
查看次数

标签 统计

awk ×1

bash ×1

linux ×1

sed ×1

shell ×1