How to Avoid intermediate files when pipe does nt work

problem with piping one output to another.Would like to avoid the intermediate file creation.The piping does nt work on places where files have been created and goes in an endless loop.

sed -e "s/^\.\///g" $LINE1| sed -e "s/\([a-zA-Z]\)/kkk\1/g" > $file1
tr -s '
' ' ' < $file1| \
sort -n -k 1.1,1.1 -k 2.1,2.8 -k 3.1,3.6 | \
awk '{ arr[$1]=$0 } END {for (i in arr) { print arr [i]} }' | \
tr '' ' ' | sort > $resultsfile
sed -e "s/ [ ]*/
/g" $resultsfile |sed -e "s/^//g"|sed -e "s/$//g"| \
grep -v "^$"|sed -e "s/kkk/_/g"| while read LINE4
do
process
done

Where is the "endless loop"?

When posting code, please put it inside

 tags, and format it so that is it easily readable. I.e., put each command on a new line with indentation to display the structure of the script and to make commenting on individual commands easier.

I've reformatted it here:
 

sed -e "s/^\.\///g" $LINE1 |
 sed -e "s/_\([a-zA-Z]\)/kkk\1/g" > $file1

Why are you using a file? Why not pipe it directly to tr?


tr -s '_' ' ' < $file1 |
 sort -n -k 1.1,1.1 -k 2.1,2.8 -k 3.1,3.6 |
  awk '   { arr[$1]=$0 }
      END {for (i in arr) { print arr } }
      ' |

If the purpose of the awk code is to remove duplicates, see below for a more efficient way to do it,

   tr '_' ' ' | sort > $resultsfile

Why are you using a file? Why not pipe it directly to sed?

sed -e "s/ [ ]*/_/g" $resultsfile |
 sed -e "s/^_//g"|
  sed -e "s/_$//g"|
   grep -v "^$"|
    sed -e "s/kkk/_/g"|

Why are you using multiple calls to sed and grep?

sed -e "s/ [ ]*/_/g" \
    -e "s/^_//g" \
    -e "s/_$//g" \
    -e "/^$/d" \
    -e "s/kkk/_/g" $resultsfile |
while read LINE4
do
  process
done

What's wrong with this:

sed -e "s/^\.\///g" \
    -e "s/_\([a-zA-Z]\)/kkk\1/g" "$LINE1" |
  sort -t_ -n -k 1,1 -k 2.1,2.8 -k 3.1,3.6 |
    awk ' { !arr[$1]++ { print } } ' |
      sort |
       sed -e 's/ [ ]*/_/g' \
           -e  '/^$/d' \
           -e 's/kkk/_/g'|
while read LINE4
do
  process
done