Reading line in while loop

Hello Team,
i have to read line by line in a while loop, and the input file has:.

 # The script will start cppunit test application to run unit tests.
-LD_LIBRARY_PATH=$CPPUNIT_HOME/lib:\
+LD_LIBRARY_PATH=$VOBTAG/SS_UnitTest/lib:\
 $VOBTAG/SS_BFD/BFDSCLI/build:\
 $VOBTAG/SS_LibPMGMT/PmgmtCAPI/build:\
 $VOBTAG/SS_LibPMGMT/PmgmtCppAPI/build:\
Index: SS_BFD/TXLDAPPlugIn/tst/cppunit/src/Main.cpp
===================================================================
--- SS_BFD/TXLDAPPlugIn/tst/cppunit/src/Main.cpp        (.../SS_BFD_4.76)       (revision 1970)
+++ SS_BFD/TXLDAPPlugIn/tst/cppunit/src/Main.cpp        (.../SS_BFD_4.82)       (revision 1970)
@@ -1,4 +1,5 @@
 #include <iostream>
+#include <cstdlib>

but my below code is generating the output with "$VOBTAG" 3 lines in a single line.

#!/bin/bash
while read line
  do
    echo $line
    echo "*****************"
  done<$1

Output:

*****************

*****************
# The script will start cppunit test application to run unit tests.
*****************
-LD_LIBRARY_PATH=$CPPUNIT_HOME/lib:+LD_LIBRARY_PATH=$VOBTAG/SS_UnitTest/lib: $VOBTAG/SS_BFD/BFDSCLI/build: $VOBTAG/SS_LibPMGMT/PmgmtCAPI/build: $VOBTAG/SS_LibPMGMT/PmgmtCppAPI/build:Index: SS_BFD/TXLDAPPlugIn/tst/cppunit/src/Main.cpp
*****************
===================================================================
*****************
--- SS_BFD/TXLDAPPlugIn/tst/cppunit/src/Main.cpp (.../SS_BFD_4.76) (revision 1970)
*****************
+++ SS_BFD/TXLDAPPlugIn/tst/cppunit/src/Main.cpp (.../SS_BFD_4.82) (revision 1970)
*****************
@@ -1,4 +1,5 @@
*****************
#include <iostream>
*****************
+#include <cstdlib>
*****************

Could you pls let me know how i can read each line separately , the input file being svn diff, i don want to consider with what the line is ending(Ex. \).

Regards,
Chandana

Try:

while IFS='' read -r line
do	printf "%s\n*****************\n" "$line"
done < "$1"
1 Like

Hi Chandana,
Could you pls let me know how i can read each line separately , the input file being svn diff, i don want to consider with what the line is ending(Ex. \).

actually your script reads each line separately and prints it along with that "********" line.

i don want to consider with what the line is ending - you mean, you dont want to read lines ending with "\", you wanted to read other lines only.. is that correct?

Actually the original script removes leading spaces and tabs; if a line ends with \, the backslash is discarded and the following line is added to the current line (repeating until a line does not end with \); removes trailing spaces and tabs; and converts any sequence of one or more spaces and tabs to a single space.

Furthermore, if (after removing leading spaces and tabs) the first character is - or if \ occurs anywhere in the line (after combining lines ending with \), the results will vary from system to system (since echo handles options and arguments containing \ differently on different systems).

1 Like

You could try something like this as well if you don't mind the trailing slash being removed:

sed 's/\\$//g' file | while read line ; do echo $line ; echo "*****************" ; done
1 Like

Thanks Don...

And if you don't mind losing slashes embedded in the line, as well as leading and trailing whitespace. Refer to post #4.

Regards,
Alister

Thanks All :slight_smile:

It worked,

It was very helpfull.

Regards,
Chandana