- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: tr and :print option
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 08:28 AM
тАО11-15-2005 08:28 AM
tr -d [^:print]
Seems to make sense to me; delete all characters that are not in the printable class.
(There is no specific info in the man page for tr about :print, but this seems to be what it says).
When I run the following data through the command:
man tr
vi find_new_histfile_lines
cd /admin/scripts/
vi find_new_histfile_lines
sh -x find_new_histfile_lines
I get the following output:
ma
v fd_ew_hsfle_les
cd /adm/scs/
v fd_ew_hsfle_les
sh -x fd_ew_hsfle_les
Does this make any sense at all? It seems like certain characters (e.g., "n", "t") are being treated as unprintable.
Scott
Solved! Go to Solution.
- Tags:
- tr
- unprintable chars
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 09:33 AM
тАО11-15-2005 09:33 AM
Re: tr and :print option
tr -d [:graph:]
"graph" is non-printable characters. Also in your sample you were missing a colon. The class would be [:print:].
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 09:34 AM
тАО11-15-2005 09:34 AM
Re: tr and :print option
I would do it like this: Note that printables include ' ' through '~' (octal 040 - 176) and you probably don't want to throw away LF's (octal 012) as well. Not that the 'c' tr option complements the string so we don't need no stinkin' '^'.
cat myfile | tr -cd "[\040-\176][\012]" > newfile
If your want to keep formfeeds and CR's as well the append their octal equivalents to the string as well (inside brackets).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 09:43 AM
тАО11-15-2005 09:43 AM
Re: tr and :print option
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 09:43 AM
тАО11-15-2005 09:43 AM
Re: tr and :print option
I was basing this on another post and what I see in the man page for "tr":
[:class:]or [[:class:]] Stands for all the characters belonging to the
defined character class, as defined by the current
setting of LC_CTYPE locale category. The following
character class names will be accepted when
specified in string1: alnum, alpha, blank, cntrl.
digit, graph, lower, print, punct, space, upper,
or xdigit
I have tried with and without the "^", and with "[" and "[[". So while I understand it seems to be omitting these characters, I wonder how I can make the class of ":print" work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 09:46 AM
тАО11-15-2005 09:46 AM
Re: tr and :print option
tr -d [:print:]
and this:
tr -d [^:print:]
The first gives me the same results, the second gives me all blanks.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2005 10:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2005 01:51 AM
тАО11-16-2005 01:51 AM
Re: tr and :print option
I was origianlly using strings, but I saw that one character commands (like "w") were being stripped out by strings. So that's why I'm looking at tr.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2005 02:03 AM
тАО11-16-2005 02:03 AM
Re: tr and :print option
cat myfile | tr -Acs "[[:print:]][\012]" > newfile
should, of course be:
cat myfile | tr -Acd "[[:print:]][\012]" > newfile