Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"Because of this forum, I continue to WOW! my clients!"

Geography

Where in the world do Tek-Tips members come from?

how to rid off leading and trailing spaces/tabs in each column?Helpful Member! 

ogniemi (TechnicalUser)
2 Jul 10 5:07

a text file contains columns delimetered with "|" sign.

example:
  aaaaaaaa  |    fffffff |       cccc  |  ddd

how to get rid off empty leading/trailing signs in each column and get in result:

aaaaaaaa|fffffff|cccc|ddd

regards.
Helpful Member!  PHV (MIS)
2 Jul 10 5:14
One way:

CODE

sed 's!^ *!!;s! *| *!|!g;s! *$!!' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

ogniemi (TechnicalUser)
2 Jul 10 6:48
thx but tabs are still kept....

CODE

$ echo "  ssss     |     sss\tsss\t   |ddd   |a"|sed 's!^ *!!;s! *| *!|!g;s! *$!!'
ssss|sss        sss     |ddd|a
$ echo "  ssss     |     sss\tsss\t   |\tddd   |a"|sed 's!^ *!!;s! *| *!|!g;s! *$!!'
ssss|sss        sss     |       ddd|a
$
p5wizard (IS/IT--Management)
2 Jul 10 7:04
Well, you'll need to specify spaces or tabs in the sed commands like so

sed 's!^[ (tab)]*!!;'

and so on. Substitute " *" with "[ (tab)]*" in PHV's example. For sed, you'll need to type the tab character literally as it doesn't understand \t.

[xyz]* means any number of the characters inside the brackets

HTH,

p5wizard

stefanwagner (Programmer)
5 Jul 10 12:16
Gnu sed understands \t on linux (at least).  

don't visit my homepage: http://home.arcor.de/hirnstrom/minis/index.html

p5wizard (IS/IT--Management)
5 Jul 10 17:52
gnu != unix winky smile

HTH,

p5wizard

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close