I read a file line by line and edit each line and save those lines in a separate file.
while read -r line
do
newline=$(echo $line | sed -r 's/\</\n/g' | sort | tr '\n' ' ')
echo "$newline" >> newfile
done < "$filename"
But I want to replace the original lines with respect to $filename
with the new lines. I read that I could use cat filename... | xargs -n1 command
or sed -i ...
but till now my trails are failed.
Here is an example input:
1.e4 e5 2.Nf3 Nc6 3.
1.d4 d5 2.e4 dxe4 3.
1.e4 e5 2.Nf3 Nf6 3.
and this is the expected output:
1. 2. 3. e4 e5 Nc6 Nf3
1. 2. 3. d4 d5 dxe4 e4
1. 2. 3. e4 e5 Nf3 Nf6