LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash tab hell (https://www.linuxquestions.org/questions/programming-9/bash-tab-hell-566409/)

Histamine 07-03-2007 04:41 PM

bash tab hell
 
I'm having problems with bash and tabs.... I keep trying:

${dta#\#}
${dta%\#}

on:

220.208.98.253 (Imagine 8 tabs here ) ERROR:"550 - REJECTED - Spammer" ( one \t ) #2007-07- 2 183

This is what I get:

220.208.98.253 ERROR:"550 - REJECTED - Spammer" #2007-07- 2 183
220.208.98.253 ERROR:"550 - REJECTED - Spammer" #2007-07- 2 183

It should give me ( According to the Advanced Bash Scripting Guide ) either:

220.208.98.253 ERROR:"550 - REJECTED - Spammer"

or

2007-07- 2 183

Its not, and its driving me nuts!! how can I pull the end off of a string? One with tabs?

TIA

pixellany 07-03-2007 05:00 PM

Can you explain what these are supposed to do?
Quote:

${dta#\#}
${dta%\#}
They are not commands, so you must be using them with...sed? awk?

Histamine 07-03-2007 05:22 PM

${dta#\#}
 
${string#substring}

Strips shortest match of $substring from front of $string.

${string%substring}

Strips shortest match of $substring from back of $string.

$dta is the string I need to parse. # is usually comments so.. \# is literal.

# string from front
% strip from back

rupertwh 07-03-2007 05:23 PM

Quote:

Originally Posted by Histamine
I'm having problems with bash and tabs.... I keep trying:

${dta#\#}
${dta%\#}

Those two lines of yours will cut off a single # from the front or back.
You forgot the wildcard *:
Code:

${dta#*\#}
${dta%\#*}

(And it has nothing to do with tabs)

Histamine 07-03-2007 05:44 PM

Thanks
 
That worked. :)

It wasn't in the examples, and I'm trying to learn a little more. Had to do something extra to get tabs, do I thought the tabs were interfering or something.

jschiwal 07-03-2007 06:37 PM

You can enter literal tabs in the shell by typing [CNTRL]v-[TAB].
That will work with other characters as well, and will work in vim as well as konsole.

Entering the TAB key by itself can trigger auto-completion instead.
For some things like regular expressions in sed & awk or using printf, you can use \t.

bigearsbilly 07-05-2007 03:31 AM

yes, remember the ${var%} type operators
accept shell type wild cards, not grep style.
i.e a char is ? not a .

As for which end of the string they are,
I remember it like this:

${var#}
a comment goes
#here

${%}
a percent goes here:
100%


All times are GMT -5. The time now is 04:10 PM.