Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    2

    Unanswered: Problems with read command

    Hi Guys,

    I have a file with the following lines

    123456789 123456789
    123456789XXXXXXXXX123456789

    All the X here are actually spaces in the actual file.


    To read this file line by line , I used the following code.

    file=test.dat
    cat $file | while read line
    do
    echo $line
    done

    In the output, I get something like this

    123456789X123456789. All but 1 space have disappeared. Actually I need the spaces in tact. Please let me know where I went wrong.

    Thanks in advance.

    Dilip

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    while read line
    do
    echo "$line" # the quotes will prevent echo removing the extra spaces
    done < test.dat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •