【发布时间】:2014-10-17 16:52:13
【问题描述】:
我写了一个简单的脚本,它读取文件内容并在这个文件中增加一个数字,然后我使用 awk 保存更改,当我尝试使用 '>' 重定向新字符串时,整个字符串是重定向在一行中,而不是像原来的那样是 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
这是运行脚本之前的原始文件:
Major Release Number = 4
Minor Release Number = 1
Service Pack Release Number = 2
Build Number = 22
这是我使用脚本后的内容:
Major Release Number = 4 Minor Release Number = 1 Service Pack Release Number = 2 Build Number = 23
我试图弄清楚如何以 4 行的原始格式重定向文本。
【问题讨论】: