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" ...
- 05-11-2011 #1Just 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
- 05-11-2011 #2
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.
- 05-11-2011 #3Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
Try looking at the output of the following:
Code:$ od -N1 file
- 05-16-2011 #4Just Joined!
- Join Date
- May 2009
- Location
- Oregon
- Posts
- 51
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.


Reply With Quote
