Visit Our UNIX and Linux User Community


sed 's/~/\^J/g' how to get "^J" on same line as rest of the command.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed 's/~/\^J/g' how to get "^J" on same line as rest of the command.
# 1  
Old 07-19-2001
sed 's/~/\^J/g' how to get "^J" on same line as rest of the command.

when ever i type it in it always looks like so

Code:
echo $file | sed 's/~/\
/g'

how can i get it on one line?
# 2  
Old 07-19-2001
... ^j is a hard return
try escaping the carrot and the j
ie: '\^\j'
why the need for it? is it some sortof global replace?
hope that helps
# 3  
Old 07-19-2001
nope didnt work.

the purpose is a client send us a file ~ denotes a carrage return in this file. It then gets emailed to another computer as the body of a mesage (sometimes this file is well over the limit for the mail program and gets mutated in the transfer) so if i replace the ~ w/ carage returns we never have this problem. BUT it has to be on one line in my preferance.
# 4  
Old 07-19-2001
well, the only other thing i can think of without actually working on it myself is to either try substituting the '^J' with a '^M' (escaping it of course - '\^\M') OR... and this may be a long shot - try double escaping it - '\\^\\J' or '\\^\\M' - that MIGHT work... (reason being is if you are calling it from a call....hence the double escaping)
# 5  
Old 07-19-2001
Also you may be able to replace the ^J with the octal code of \015 (which is actually the same as a ^M)

I had the same issue as this a year or so ago and the octal code worked where the ^J did not, but then again there may be issues with using the ^J (linefeed) vs ^M (carriage returm)
# 6  
Old 07-19-2001
answer:

Code:
tr '~' '\12'

man tr

# 7  
Old 07-19-2001

What about using ctrl-v ctrl-j ? This works under bash in Linux, and ksh on HP-UX for sure. Ctrl-v makes the next character literal, not interpreted as the control-command.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #215
Difficulty: Easy
Cisco IOS has a monolithic architecture.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

2. Shell Programming and Scripting

What are the differences between 'bash' and 'sh'

Hopefully this doesn't come off as too much of a "newbie" question or a flamebait. But I have recently begun working with a Sun Solaris box after having spent the past five years working with RedHat. From what i can tell, thing look fairly similar and the 'man' command is some help. But I've... (7 Replies)
Discussion started by: deckard
7 Replies

3. UNIX for Advanced & Expert Users

How to remove a file with a leading dash '-' in it's name?

Somehow someone created a file named '-ov' in the root directory. Given the name, the how was probably the result of some cpio command they bozo'ed. I've tried a number of different ways to get rid of it using * and ? wildcards, '\' escape patterns etc.. They all fail with " illegal option --... (3 Replies)
Discussion started by: GSalisbury
3 Replies

4. Programming

Couldn't compile the simple "Hello World"

So, this is my first C++ program under linux. My OS is Red Hat 8.0, and my codes are like following: $vi hello.cpp #include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; return 0; } $ g++ -o hello hello.cpp the error message are: ... (3 Replies)
Discussion started by: HOUSCOUS
3 Replies

5. UNIX for Dummies Questions & Answers

quoting echo 'it's friday'

echo 'it's friday' why appear the > (3 Replies)
Discussion started by: yls177
3 Replies

6. Filesystems, Disks and Memory

Why i can't use the tool "turbosoundcfg" to configure the sound in my TurboLinux?

But the page "http://www.chinalinuxpub.com/doc/tlc61/node60.html" says it can.Why ?What can i do? Help me ! Thanks a lot! (3 Replies)
Discussion started by: sensir163
3 Replies

7. UNIX for Dummies Questions & Answers

i don't understand the "sort" command

i have been trying to understand this chapter titled "Searching for Files and Text" for a few weeks now. unfortunately, this chapter is one of those things, that no matter how hard you try and how long you try for, you are incapable of understanding (at least in my case) this entire chapter,... (2 Replies)
Discussion started by: xyyz
2 Replies

8. Shell Programming and Scripting

Clearify what it means under 'WHAT' when hit the 'w'-command

I wonder how I shall read the result below, especially 'what' shown below. The result was shown when I entered 'w'. E.g what is TOP? What is gosh ( what does selmgr mean?)? login@ idle JCPU PCPU what 6:15am 7:04 39 39 TOP 6:34am 6:45 45 45 TOP 6:41am ... (1 Reply)
Discussion started by: Aelgen
1 Replies

9. UNIX for Dummies Questions & Answers

'find' command question

my solaris text talks about the 'find' command... it further goes to talk about an "action" used with the find command. I am completely confused as to what the {} do with the find comand. the explanation is this: "A set of braces, {}, delimits where the file name is passed to the command from... (2 Replies)
Discussion started by: xyyz
2 Replies

10. UNIX for Dummies Questions & Answers

what is the 'whatis' command?

I am kind of new with Unix and I really need some help. Can you please tell me what the 'whatis' command is? and what does it do? Let's say that I have a file which I want to delete, what command will I need to use? If I have a directory that I want to delete all files from what command do... (11 Replies)
Discussion started by: mischiefdemon
11 Replies

Featured Tech Videos