Bash: How to read tab character when reading input
Hello,
i'm new to bash and searched the forum before asking this question. I'm reading input from a file line by line, however i need to check if the first string of a line is preceded by a tab. i'm using following code to read input line by line, but this ignores any whitespace/tab at the begining and end of the line. can anyone plz help me? line="" while read line do parseLine $line; done < <(cat $1) |
"read" is already somewhat parsing the line in words. Tab being by default a separator is not making it to the line variable.
You can remove tab from the separators with using IFS=" ", or you can really read a better way the whole line with the "line" command: while line=$(line) |
You could use head to read a line.
Code:
line=$(head -n 1) Code:
echo "$line" | od -tc Code:
0000000 h e l l o \t w o r l d \n |
thanks a lot for the replies. i'll try these out.
|
Quote:
i tried if [ $1 = "\t" ] it didn't work |
A portable way would be:
Code:
if [ "$(expr $1 : '\(.\)'" = "<TAB>" ] Code:
if [ "${1:0:1}" = "<TAB>" ] |
Hi.
Here is a script that illustrates the setting of TAB into a variable, the use of IFS to allow reading of TABS, and the test for a single TAB character ... cheers, makyo Code:
#!/bin/sh |
thanks thanks thanks a lot to jlliagre and makyo. you guys really healped me. it worked!!! you guys are great. its tough being a newbie and help from ppl like you gets us going. thanks again.
|
All times are GMT -5. The time now is 07:57 AM. |