Linux - Bash Redirect a String to a file

Posted by user3502786 on Stack Overflow See other posts from Stack Overflow or by user3502786
Published on 2014-08-24T10:19:15Z Indexed on 2014/08/24 10:19 UTC
Read the original article Hit count: 169

Filed under:
|
|
|
|

I wrote a simple script that is reading the file content and incrementing a a number inside this file, then i'm holding the change using awk, when i'm trying ro redirect the new String using '>' the whole string is redirected in one line and not like the original was which is 4 lines.

#!/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

This is the original file before running the script:

Major Release Number = 4
Minor Release Number = 1
Service Pack Release Number = 2
Build Number = 22

This is the content after i used the script:

Major Release Number = 4 Minor Release Number = 1 Service Pack Release Number = 2 Build Number = 23

I'm trying to figure out how can i redirect the text in the original format which is 4 lines.

© Stack Overflow or respective owner

Related posts about linux

Related posts about bash