LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-03-2007, 04:41 PM   #1
Histamine
LQ Newbie
 
Registered: Jun 2007
Posts: 20

Rep: Reputation: 0
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
 
Old 07-03-2007, 05:00 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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?
 
Old 07-03-2007, 05:22 PM   #3
Histamine
LQ Newbie
 
Registered: Jun 2007
Posts: 20

Original Poster
Rep: Reputation: 0
${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

Last edited by Histamine; 07-03-2007 at 05:24 PM.
 
Old 07-03-2007, 05:23 PM   #4
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
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)
 
Old 07-03-2007, 05:44 PM   #5
Histamine
LQ Newbie
 
Registered: Jun 2007
Posts: 20

Original Poster
Rep: Reputation: 0
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.
 
Old 07-03-2007, 06:37 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 07-05-2007, 03:31 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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%
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab in bash script Bobb3 Linux - Newbie 12 10-25-2013 02:42 AM
Tab width in Bash - how do I set it benr77 Linux - General 8 12-04-2012 10:53 AM
Bash script using tab complete sadarax Programming 6 01-30-2007 08:21 PM
bash - how to open a new shell tab infraredgirl Programming 4 03-30-2006 07:23 PM
bash "tab tab" - how to turn off? nicflatterie Linux - General 2 04-04-2005 03:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration