The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing a character string in a file rjsha1 Shell Programming and Scripting 13 04-11-2009 01:07 PM
Null Character Handling npk2210 Shell Programming and Scripting 3 09-29-2007 04:51 AM
replacing the character "\" in a file rjsha1 Shell Programming and Scripting 5 01-11-2006 09:45 AM
Find files which contain a null character Bab00shka UNIX for Dummies Questions & Answers 5 12-16-2005 10:41 AM
sending a null character to a terminal vertigo23 UNIX for Advanced & Expert Users 3 09-30-2005 09:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-16-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Question Replacing character in file with null value

What is the null value's character to replace in the following syntax?
---
Command: cat filename | tr "charactertoreplace" "nullvalue" > newfilename
===
After googling, searching in this forum, and asking local in-house programmers regarding the question, the closest I got to was just simply "null" (without the quotes, i.e.
---
cat afilename | tr "\n" null > newafilename
===
However, that did not do the same thing that GUI-based editors like Textpad, and UltraEdit does. Is there a way to achieve this task that can be scripted when wanting to apply the action to multiple files? Please assist.

Thanks!
  #2 (permalink)  
Old 06-16-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
tr -s '\n' '\000' < oldfile > newfile
  #3 (permalink)  
Old 06-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
are you trying to substitute with the ASCII 'NUL'? [I'm not sure]

if that's the case 'tr' can take octal representations:
Quote:
Originally Posted by man tr
\octal A backslash followed by 1, 2 or 3 octal digits represents a
character with that encoded value. To follow an octal
sequence with a digit as a character, left zero-pad the octal
sequence to the full 3 octal digits.
'NUL' in octal is '000'.

tr '\n' '\000' < afilename >newafilename
  #4 (permalink)  
Old 06-26-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Replacing ^U character with newline

Quote:
Originally Posted by vgersh99
are you trying to substitute with the ASCII 'NUL'? [I'm not sure]

if that's the case 'tr' can take octal representations:


'NUL' in octal is '000'.

tr '\n' '\000' < afilename >newafilename
Thanks! Works like a charm. Would octal representations handle replacing values like ^M, ^U, etc.? I'm trying to replace ^U at the moment with a newline character, but can't seem to find out how to specify the "^U" in the tr -s command. Where can I find a list of the special characters and their corresponding values for such tasks?
  #5 (permalink)  
Old 06-26-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
try 'man ascii'
  #6 (permalink)  
Old 06-26-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Quote:
Originally Posted by vgersh99
try 'man ascii'
Thanks! Because I'm seeing the phrase ^N when I view the file with the less command, and the octal values for ^ and N are respectively 136 and 116, how would I combine the two to have it replaced by a '\n'?
  #7 (permalink)  
Old 06-26-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
$ echo '^N' | od -c
0000000  016  \n
0000002
for '^N':
Code:
tr '\016' '\000' < afilename >newafilename
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0