Tips on using bash script to edit a windows text file
I have a bash script executing on an AIX server to a windows share directory to update a windows text file. Most of the file is edited as expected but I have 3 issues that I am not sure how to resolve.
1. Windows text file contains a double backslash (\\) and the \\ is being written back as a single \ which corrupts the file. 2. I am not getting the last line of text in the file written back out. 3. Some lines of text are not written back out completely. Here is a snippet of my bash script: cp $Directory/Somefile $Directory/Somefile.$(date +'%Y%m%d') cat /dev/null > ${HOME}/temp.out while read -r inpLine; do patternFound=n echo ${inpLine} | grep -q 'SOMEPATTERN=' if [ $? = 0 ]; then patternFound=y echo "##${inpLine}" >> ${HOME}/temp.out echo "SOMEPATTERN=newValue" >> ${HOME}/temp.out fi if [ ${patternFound} = "n" ]; then echo ${inpLine} >> ${HOME}/temp.out fi done < $Directory/Somefile mv ${HOME}/temp.out $Directory/Somefile |
Quote:
Code:
~]$ echo "\\\\" Quote:
Quote:
|
Maybe a stupid idea, but running dos2unix on the file before editing the file and unix2dos afterwards might solve some compatibility problems.
Awk is better suited for this task, but if this project is only one of a kind it might not be worth the effort to learn it. And please post code snippets in [.CODE][./CODE] tags. jlinkels |
Sorry I am new to forum and didn't read the rules about how to appropriately post code snippets. Also very new to AIX/Linux and bash.
The resolution to my issue was to change from echo approach to sed and handle the special characters. |
All times are GMT -5. The time now is 12:13 PM. |