How to insert numbers to a in between statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to insert numbers to a in between statement
# 8  
Old 06-19-2011
Hi
You have already posted the same question under a different thread. It is not right to do double posting. Anyways, here is the answer:


Code:
$ cat a
1111111111
2222222222
3333333333


$ sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #!/bin/bash \n' a
#!/bin/bash

website 111111111.1.numbers.com
website 222222222.2.numbers.com
website 333333333.3.numbers.com

Guru.
# 9  
Old 06-19-2011
Quote:
Originally Posted by guruprasadpr
Hi
You have already posted the same question under a different thread. It is not right to do double posting. Anyways, here is the answer:


Code:
$ cat a
1111111111
2222222222
3333333333


$ sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #!/bin/bash \n' a
#!/bin/bash

website 111111111.1.numbers.com
website 222222222.2.numbers.com
website 333333333.3.numbers.com

Guru.

Hi Guru,

Yes. I should remove that other thread and maintain this one. Anyways, below is the response I'm getting...

Code:
$ sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #!/bin/bash \n' a
/bin/bash: Event not found.


Thanks again.


Br,
Pinpe

Moderator's Comments:
Mod Comment I have closed your other thread, and linked it to here

Last edited by Scott; 06-19-2011 at 12:07 PM.. Reason: Closed other thread
# 10  
Old 06-19-2011
Hi
I think you are using csh or tcsh, and hence the exclamation(!) is creating this issue. Escape it with a backspace:

Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #\!/bin/bash \n' a

Guru.
# 11  
Old 06-19-2011
Quote:
Originally Posted by guruprasadpr
Hi
I think you are using csh or tcsh, and hence the exclamation(!) is creating this issue. Escape it with a backspace:

Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #\!/bin/bash \n' a

Guru.

Hi Guru,

This is the error now as shown below.

Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #\!/bin/bash \n' a
sed: command garbled: 1i #!/bin/bash \n


Br,
Pinpe
# 12  
Old 06-19-2011
Hi

Not sure why you are getting the error. Not able to reproduce the error in which ever shell I tried. An alternate:

Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' a | awk 'BEGIN{print "#!/bin/bash\n"}1'

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 13  
Old 06-19-2011
Quote:
Originally Posted by guruprasadpr
Hi

Not sure why you are getting the error. Not able to reproduce the error in which ever shell I tried. An alternate:

Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' a | awk 'BEGIN{print "#!/bin/bash\n"}1'

Guru.

Hi Guru,

This works for me provided that I need to used nawk instead of awk and escape the (!) because I'm on tcsh. Thanks so much dude! Smilie Smilie

Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' a | nawk 'BEGIN{print "#\!/bin/bash\n"}1'


Br,
Pinpe
# 14  
Old 06-19-2011
Quote:
Originally Posted by pinpe
Code:
sed -e 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' -e '1i #\!/bin/bash \n' a
sed: command garbled: 1i #!/bin/bash \n

Quote:
Originally Posted by guruprasadpr
Not sure why you are getting the error. Not able to reproduce the error in which ever shell I tried
A few candidates to consider:

1. The dot in replacement text is not special. You do not need to backslash-escape it in that context. Backslash-escaping non-special characters yields undefined sequences which can cause problems with some implementations (and opens the door to the remote possibility that a future extension to the standard will break current sed scripts).

2. The insert (i) command should be followed by backslash and newline, before the text to insert. (GNU sed supports text immediately after the command name but this is not portable.)

3. In a strictly compliant implementation, the \n escape sequence is only allowed in a regular expression evaluated against the pattern space. It is not allowed in replacement text nor in addresses. As with the \. sequence mentioned above, \n in in those contexts yields an undefined sequence (GNU sed will probably emit a newline). However, within the text argument to the insert (i) and append (a) commands, backslashes are stripped and the following character treated literally. \! becomes ! and \n becomes n (GNU sed instead chooses to emit a newline).

GNU sed developers may call these extensions, but they're more like incompatible deviations. Just a little one-liner and look at all the potential gotchas. What a headache!

Regards,
Alister

Last edited by alister; 06-19-2011 at 04:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert random numbers into each line?

I have a file contains thousands of lines. I want to insert n random numbers into each line at specific position. Like this: 0 22…… 1 33…… …… …… I want to insert 3 random numbers from position 2 to 4 into each line. 0 325 22…… 1 685 33…… …… …… Please use CODE tags when... (8 Replies)
Discussion started by: hhdzhu
8 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

How to insert date in a statement?

Hi Guys, Can somebody help me in inserting today's DATE format (20110709) in my awk statement. I have a script but its not working. inputfile.txt: 269,1,0,AAA,430 231,2,0,BBB,430 252,3,0,CCC,430 214,4,0,DDD,430 script.sh #!/bin/bash DATE="`date +%Y%m%d`" cd /var/opt/ (8 Replies)
Discussion started by: pinpe
8 Replies

4. Programming

Assign variable for INSERT INTO statement

Hello, Can anyone tell me that, How can I assign variable to shell script variable, which i need to use in INSERT INTO statement? my shell script variables are, EMPNAME=`regular expression` EMPID=`regular expression` EMPBDATE=`regular expression` Now through ksh script I am... (16 Replies)
Discussion started by: Poonamol
16 Replies

5. Programming

Dynamic Insert statement

I have a form , where i will put the values to a table. I wrote a insert statement for the same. Table structure is ename | character varying(30) | eadd | character varying(30) | eid | integer | sal | integer In the statements, i don't... (1 Reply)
Discussion started by: pritish.sas
1 Replies

6. Shell Programming and Scripting

error in insert statement

hi, When i try to run the code below, i get the following error "ksh: syntax error: `(' unexpected" i am not able to figure it out. Can anyone help me? Code: (2 Replies)
Discussion started by: ragavhere
2 Replies

7. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

8. Shell Programming and Scripting

Script does not execute Insert Statement

Hi I have a text file , contents are Line1:field1,field2,field3,field4,field5,field6.......field20 Line2:field1,field2,field3,field4,field5,field6.......field20 Line3:field1,field2,field3,field4,field5,field6.......field20 ....and so on... I want to read this file and insert the data into... (4 Replies)
Discussion started by: Amruta Pitkar
4 Replies

9. Shell Programming and Scripting

Insert TAB in echo statement

Hi, Can some1 help me to output a tab in an echo statement. I have tried echo "RNC: \t NODEB" but dont get the correct output. I am a beginnger to unix, so pls hold back the laughs....if u can (5 Replies)
Discussion started by: sunils27
5 Replies

10. Shell Programming and Scripting

awk command for INSERT statement

Hi, I sometimes bulk upload data in oracle. The problem is that I sometimes get an INSERT statemnt like this: INSERT INTO ALL_USER_HOTSPOT_DETAILS (USR_LOGIN,USR_LASTNAME,USR_FIRSTNAME,USR_EMAIL, PROPERTYNR) VALUES ('SABRDAG','D'AGOS','SABRINA','sabrina_d'agos@sheraton.com',70) I... (4 Replies)
Discussion started by: nattynatty
4 Replies
Login or Register to Ask a Question