Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reading line from file which holds braces and comma

in ksh I have a input file that holds the following:

$ cat input.txt
A {111 222 111}
B {333,444,333}
C {555 666 555}
$

When I Run the following command Im getting the following

$ while read LINE
> do 
>   echo $LINE
> done<input.txt
A {111 222 111}
B 333 444 333
C {555 666 555}
$


How to insure to read lines as is with braces and comma?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In order to avoid special syntax with braces and coma in ksh when you are doing an echo, add quotation marks around $LINE:

while read LINE
do 
    echo "$LINE"
done<input.txt

The syntax {1,2,3...} is useful for loops:

for x in {1,a,3}; do echo x=$x; done
x=1
x=a
x=3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading