LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-08-2021, 12:46 AM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,834

Rep: Reputation: 108Reputation: 108
Future "tr" users, read this thread,


Hya,

Expected readers: tr users, not quite power users

Situation: You want to manipulate "-" (hyphen)

Read this thread!

It may be a special character (range), as regex. You can escape with '\'

I ran into this situation, and took several days to settle down.

I only checked man page. You should read info page also!

Have a happy penguin!

Last edited by kaz2100; 10-17-2021 at 08:37 PM. Reason: grammar
 
Old 10-08-2021, 12:55 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
would be nice to show a [real] example
 
Old 10-08-2021, 03:37 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by kaz2100 View Post
You can escape with '\'
Yep, escaping characters is very common and can be very useful with all sorts of CLI utilites, shells, etc.
Not at all specific to tr.
 
Old 10-10-2021, 07:06 PM   #4
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,834

Original Poster
Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by pan64 View Post
would be nice to show a [real] example
Following, how I ran into trouble
Code:
cat someFile | tr -d '/-_'
Yes, it is important, so I checked man file. I know who was careless.
 
Old 10-11-2021, 01:10 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
but the solution is wrong.
Code:
cat someFile | tr -d '\-_'
you need to use backslash instead of forward slash. What you wrote will remove / too.
From the other hand
Code:
cat someFile | tr -d '_-'
# and
cat someFile | tr -d -- '-_'
will work too
 
Old 10-11-2021, 03:53 PM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,806

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
An embedded dash makes tr recognize a range.
Putting the dash first makes tr recognize an option.
Workarounds:
Code:
tr -d '/\-_'
tr -d -- '-/_'
tr -d '/_-'
 
Old 10-11-2021, 06:31 PM   #7
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,834

Original Poster
Rep: Reputation: 108Reputation: 108
Hya,

Thanks for your comments.

Yes, I lost everything between '/' and '_' (inclusive) with
Code:
cat someFile | tr -d '/-_'
and it took long for me to figure out. This is the reason for this thread.

All intended readers in future can save more time with these comments.

Take home message:
Penguins, read this thread before you run into this trouble.
 
Old 10-15-2021, 01:37 PM   #8
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Yep, reading all the info available with man and info helps.
Also,
Have a backup of the original so you don't muck something up!
is always a good idea.
 
  


Reply

Tags
escape, hyphen, set, tr



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
Thread read/not read TheStarLion LQ Suggestions & Feedback 3 03-14-2010 09:40 AM
[LQ Spy] - could it show the icon per-thread for "You Are Subscribed To This Thread"? GrapefruiTgirl LQ Suggestions & Feedback 5 08-22-2009 01:19 PM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
[thread control suggestion] add a "solved" button that the thread starter can click atom LQ Suggestions & Feedback 3 03-24-2005 11:55 AM
How to set a Gnome theme as default for all users and future users ? MDesigner Linux - Newbie 1 06-28-2004 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:48 PM.

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