Find the answer to your Linux question:
Results 1 to 2 of 2
Hey all, I'm wondering why the following returns what it does.. bash -x tells me: Using cut: Code: test=`cat avvdat.ini | grep avvdat-*.zip | cut -d= -f2` test=$'avvdat-6477.zip\r' Same with ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2007
    Posts
    6

    Question cat+grep+sed/cat+greg+cut output to variable


    Hey all,

    I'm wondering why the following returns what it does..

    bash -x tells me:

    Using cut:

    Code:
    test=`cat avvdat.ini | grep avvdat-*.zip | cut -d= -f2`
    
    test=$'avvdat-6477.zip\r'
    Same with sed:

    Code:
    test=`cat avvdat.ini | sed -n '1,/^FileName/ s/^.*avv/avv/1p'`
    
    test=$'avvdat-6477.zip\r'

    But if I echo, I get right what I want

    Code:
    echo $test
    
    avvdat-6477.zip
    Basically I'm comparing it to a file name, and I'm getting results telling me that that the two are different, because of how the variable is formulated.

    Thanks in advance,

    Chris

  2. #2
    Just Joined!
    Join Date
    Aug 2011
    Posts
    51
    You might have a dos2unix issue. Run dos2unix and try your script again.
    If that doesn't work use od -tx1 -c <filename> to see what the end of line is. Linux, it would be 0x0a.
    You will have to change your sed command to handle the extra char that is in the file.

Posting Permissions

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