Hi All,
I am new to Shell scripting.. I have a task to parse the text file into csv format. more then half the things has done.
But the problem is when I use the sed command in shell script. it appends newline character at the end of the line. and so when I open the file in CSV it's format is not as what I want..
I have the test file like
input.txt
test-1;1;1;100Mb/s
test-2;1;2;
test-1;2;2;
test-2;2;3;
test-2;3;4;
and I want to replace the data in the third column with some text ( it's in other file, info.txt) . And for that I am using the following shell script
info.txt
Result 1 Pass
Result 2 Fail
Result 3 Unknown
Result 4 Crash
Shell Script
exec < info.txt
while read line; do
echo $line > tmp
fnd=`awk '{print $2}' tmp`
rep=`awk '{print $3}' tmp`
echo "c=$fnd d=$rep"
sed -i 's/test-[1-9],[1-9],'$fnd'/&'$rep'/' input.txt
sed -i 's/'$fnd$rep'/'$rep'/' input.txt
done
After the above code I wish the input.txt file to be like below
test-1,1,Pass,100Mb/s
test-3,1,Fail,200Mb/s
test-1,3,Unknow,150Mb/s
test-1,3,Crash,150Mb/s
But when I open it in the text editor I found it like below
It appends extra newline character after the pattern find and replace
test-1,1,Pass
,100Mb/s
test-2,1,Fail
,
test-1,2,Fail
,
test-2,2,Unknown
,
test-2,3,Crash
Crash
And so when I export it to CSV file the format just ruins...
Please Please help me.
Thnx in advance ...