Ctrl-V + Ctrl-J for newline character does not work inside vi editor


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Ctrl-V + Ctrl-J for newline character does not work inside vi editor
# 1  
Old 12-14-2012
Ctrl-V + Ctrl-J for newline character does not work inside vi editor

Hi friends,

I am trying to add a newline char ('\n') between the query and the commit statement in the following shell script.
Code:
#! /bin/sh
echo "select * from tab; commit;" > data.sql

I have tried typing in "Ctrl-V + Ctrl-J" combination which has inserted ^@ (NUL) character but the commit statement is not in its own line as expected when I see the contents of data.sql file. I have even tried with "Ctrl-V + Ctrl-M" which has inserted ^M character but still I could not see the result. The output is completely weird this time.
Code:
$ cat data.sql
commit; elect * from tab;


I know, I can get the expected output through this:
Code:
echo -e "select * from tab;\ncommit;" > data.sql


Yet I want to achieve it through "Ctrl-V" key combination. Is that possible? Could anyone help me?

I am expecting the output to be like this
Code:
$ cat data.sql
select * from tab;
commit;


Last edited by royalibrahim; 12-14-2012 at 12:30 PM..
# 2  
Old 12-14-2012
You are overthinking this. If you want a literal newline to be inside your string, hit your ENTER key.

That is what a literal newline character in the middle of your string really looks like:

Code:
echo "select * from tab;
commit;"

...because that's what newline does. You won't be able to 'trick' it into being on a single line.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

2. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

3. Shell Programming and Scripting

Ctrl-C or Ctrl-Z causing exit the session

H! I have written script where it need to invoke the perl script in background, then write the pid in temp file then bring back the job to foreground. whenever the Ctrl-C or Ctrl-Z is pressed in the script has to exit and prompt should be dispalyed. but this script causing exit from shell session... (2 Replies)
Discussion started by: jramesh1
2 Replies

4. UNIX for Dummies Questions & Answers

ctrl-o in bash on os X leopard -- how does it work exactly?

I'm going through "learning the bash shell" by newham and rosenblatt. I'm trying to ctro-O to execute and then go on to the next command in the history list, ctrl-o again, etc. (I'm just trying to get a feel for it in case I want to use it). But ctrl-o does nothing. Can someone help me out as to... (5 Replies)
Discussion started by: Straitsfan
5 Replies

5. UNIX for Dummies Questions & Answers

CTRL/C does not work

Hi My CTRL/C does not work thought the STTY setting looks Ok Appreciate your assistance $stty -a speed 38400 baud; rows = 24; columns = 80; ypixels = 0; xpixels = 0; eucw 1:0:0:0, scrw 1:0:0:0 intr = ^c; quit = ^\; erase = ^?; kill = ^u; eof = ^d; eol = <undef>; eol2 = <undef>;... (10 Replies)
Discussion started by: zam
10 Replies

6. Shell Programming and Scripting

What is the meta character for the Ctrl button?

In this script I have, it says press Ctrl+W+? for help, but it doesn't do anything. I looked in the script and it binds: bind ^W meta2_character. How do I make it the Ctrl button so I can do Ctrl+W? (There are some other commands that use Ctrl+W+another character/letter/number.) (4 Replies)
Discussion started by: guitarscn
4 Replies

7. Shell Programming and Scripting

Adding CTRL-M Character

Hi, I have file generated in HP-UNIX environment (for Example) with the line feed (i.e $): a$ b$ C$ Now, I need to append CTRL-M character at the end of each line, but the last line of the file should not have both CTRL-M and Line Feed (i.e ^M and $). The file should look like: a^M$ b^M$... (2 Replies)
Discussion started by: mohan.nadaraja
2 Replies

8. Shell Programming and Scripting

Disabling ctrl-Z key inside shell script

Hi I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key. How to proceed this? Need reply soon (11 Replies)
Discussion started by: suganthic
11 Replies

9. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies

10. UNIX for Dummies Questions & Answers

my ctrl+c doesn't work

it seams that my ctrl+c and my ctrl+d don't work. if I type a bunch of jiberish on a line and ctrl+c I expect the command to be cancelled and to be given a fresh prompt, but instead it just putts ^C at the end of the line. Also, ctrl+d should close the session, but instead mine just puts ^D at... (3 Replies)
Discussion started by: yankee428
3 Replies
Login or Register to Ask a Question