- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- strange characters in a file
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
Forums
Discussions
Discussions
Discussions
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
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
05-20-2003 05:49 AM
05-20-2003 05:49 AM
how can i remove any line that contains a strange character? ...basically each line should only contain alphanumerics and maybe a "-", "_", or some other reasonable character
attached is an example file with some of these strange characters
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 05:53 AM
05-20-2003 05:53 AM
Re: strange characters in a file
Run the dos2ux command on the file in question. Looks like this file was transferred from a PC to a UX box.
Regards,
RZ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 05:56 AM
05-20-2003 05:56 AM
Re: strange characters in a file
# dos2ux badfile > goodfile
Man "dos2ux" for greater details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 06:10 AM
05-20-2003 06:10 AM
Re: strange characters in a file
ux2dos also exists!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 06:52 AM
05-20-2003 06:52 AM
Re: strange characters in a file
tr -d '[\200-\377]'
This command deletes ("-d") all the non-ASCII characters (all characters from 200 through 377 octal).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:03 AM
05-20-2003 07:03 AM
Re: strange characters in a file
If you want to analyze the contents of your file some more, you could use 'cat -v' to expose the non-printing characters. See the man pages for 'cat' and 'ascii(5)' to understand the interpretation.
Too, you may find 'xd' quite useful too. Have a look at it's man pages.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:38 AM
05-20-2003 07:38 AM
Re: strange characters in a file
Frank: i am aware of "tr -d ..." but thx for those octal codes ...yet they had no effect on this file (and also "tr" will not delete the line i think unless the new line character is referenced too?)
James: yes, "cat -v ..." shows the strange characters, and i can use "xd" and "od" to get octal values for these strange charatacters ...but i do not know what all the starnge characters may be or could be later (like Frank's idea of a range ...or the inverse of it?)
i thought there might be an easy one liner using grep with reg. expr. or something else tricky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:48 AM
05-20-2003 07:48 AM
Re: strange characters in a file
As I hinted, you will need to resort to consulting the ASCII table (man 'ascii(5)').
Some additional help is offered by 'xd -t a' which creates output as "named characters".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 10:05 AM
05-20-2003 10:05 AM
Re: strange characters in a file
Interesting. We have encountered ^? and many other strange characters when sending a file via ftp from our mainframe to unix.
It appears there is no unix translation for certain hex characters, in our case, and we end up with the "strange characters.
As a result, we have scripted the following to translate to readable chacters without destrying the data. In many cases, these strange characters are simply field delimiters in our cases.
As noted in previous post, we too use the cat -v for the translation process.
Translate i.e.
cat -v filename | sed 's/^M/~/g' | sed 's/\^M/~/g' > new_filename
The above would translate a control M and a caret M to a tilde.
Note: You can pipe as many sed statements as necessary with other "strange" character translations prior to output to the new file.
Best of luck.
Regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 11:02 AM
05-20-2003 11:02 AM
Re: strange characters in a file
cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 11:11 AM
05-20-2003 11:11 AM
Solutionperl -pe 's/[^\040-\176\012]//g' oldfile > newfile
You might want to add \014 after \012 to also allow ASCII FF's in addition to the LF's. Basically anything that ain't space through tilde (octal 40 thru 176) or a LF (octal 12) gets throwed away.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 01:03 AM
05-21-2003 01:03 AM
Re: strange characters in a file
I take it that you want to ignore lines with certain characters rather than do actual conversion. If correct, then try the attached script. You can define any which character to prevent a input line from from being printed in the CHAR_LIST variable. If you want to use a character that has another meaning than the literal as a regular expression, it must be preceeded by backslash ($ even by two).
Run the script like this:
# attached_script.sh inputfile
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 06:50 AM
05-21-2003 06:50 AM
Re: strange characters in a file
Tom D. has the 10 point answer.
I wish this thread had appeared a month ago.
Tom's solution would have saved me a lot of heart ache.
For our needs in the example I state, I will still need to do some form of substitution, but in other jobs, Tom's solution will be of great help.
Thanks Tom.
Best regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 08:04 AM
05-21-2003 08:04 AM
Re: strange characters in a file
:1,$s/^v^m//
...note, in vi, to type the ascii carriage return, ^M, you must break it down such as the carrot, ^, type
For a quick perl script that mimics the dos2ux command:
perl -pe -l.lfcr "s/[\012\015]//;" file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2003 04:53 AM
05-22-2003 04:53 AM
Re: strange characters in a file
A simple solution for this would be
cat
Regards!!
Dipu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2003 09:30 AM
05-22-2003 09:30 AM
Re: strange characters in a file
Nice confirmation of Dan's already suggested solution minus the OBVIOUS output to newfile!!!
Sorry forum, no coffee yet.
grumpy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2003 08:31 PM
05-22-2003 08:31 PM
Re: strange characters in a file
man ascii //very helpful
cat
Dave: thx for the sed reference, but in the end found other commands given in this thread to be better suited
Tom: very cool command, yet does not do a good job with the "esc" character (\033) ...i would have given you a 10 but Clay took it away
Clay: i think when perl is used its like cheating...
this was a great one liner and gives me the flexibility to control the search and action (your one-liner got all the strange characters in the file i was dealing with)
John: i like you script idea, just was having some problems with using "grep" against certain entries in $CHAR_LIST (even the ones given in your script were making grep unhappy)
Brain: thx for the tips ...i had trouble with the perl options you gave (warning: i am not that familiar with perl) and when i got it working it was not as thorough as Clay's one-liner
Dipu: "col" is a nifty little command
...now they don't feel like strange characters anymore