Find the answer to your Linux question:
Results 1 to 4 of 4
Hi helper, I have a file with one line. I want to check whether the first character is TAB or space, how can i do this...? Please help, using "cut" ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3

    Wants help please !!

    Hi helper,

    I have a file with one line.
    I want to check whether the first character is TAB or space, how can i do this...?


    Please help, using "cut" wont help me as it "bypasses the tab and space characters"


    Regards
    Varun Isac

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,097
    hi and welcome.

    One word beforehand: Please do not doubblepost.

    As for your problem:
    egrep and a characterclass will help you
    Code:
    man egrep
    egrep '^[[:blank:]]' <FILE>
    You must always face the curtain with a bow.

  3. #3
    Linux Newbie
    Join Date
    Mar 2010
    Posts
    121
    Try looking at the output of the following:

    Code:
    $ od -N1 file

  4. #4
    Just Joined!
    Join Date
    May 2009
    Location
    Oregon
    Posts
    51
    Quote Originally Posted by varunisac View Post
    Hi helper,

    I have a file with one line.
    I want to check whether the first character is TAB or space, how can i do this...?


    Please help, using "cut" wont help me as it "bypasses the tab and space characters"



    Regards
    Varun Isac
    Using BASH shell, you can execute grep, as in:

    if grep $'\x09' filename; then echo "yes it's a tab and not a space"; fi

    or perhaps...

    if grep $'\x20' filename; then echo "yes it's a space and not a tab"; fi

    if you want it to be the first character of a line that contains more than one character....

    if grep -e $'^\x20' filename; then ....

    And there are more possibilities if you are interested in dealing with a multi-line file. And there are more programs besides grep, eg: sed, awk, perl, php, that can do this type of matching as well.

Posting Permissions

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