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
# 1  
Old 06-17-2011
How to insert numbers to a in between statement

Hi Guys,

I want to create a shell script that will give me the output below. I want to insert the numbers from the input file to my url addresses below. And from the numbers below, I want to separate the last digit with a period (i.e. from 222222222222 to 22222222222.2). Appreciate any help.

Input file:
[code]
111111111111
222222222222
333333333333
[code]


Output file:
Code:
website 11111111111.1.numbers.com
website 22222222222.2.numbers.com
website 33333333333.2.numbers.com


Thanks in advance.


Br,
Pinpe
# 2  
Old 06-18-2011
Hi


Code:
$ cat a
111111111111
222222222222
333333333333


$ sed 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' a
website 11111111111.1.numbers.com
website 22222222222.2.numbers.com
website 33333333333.3.numbers.com


Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 06-18-2011
One more method

Code:
awk '{_l=length;_1=substr($1,_l-2,1);_2=substr($1,0,_l-1);print"website "_2"."_1".numbers.com"}' infile

regards,
Ahamed
# 4  
Old 06-18-2011
may be again simple..

Quote:
Originally Posted by pinpe
Input_file:
[code]
111111111111
222222222222
333333333333
[code]

Code:
awk '{print "website "$1 "." NR ".numbers.com"}' Input_file

Output file:
Code:
website 11111111111.1.numbers.com
website 22222222222.2.numbers.com
website 33333333333.3.numbers.com


Thanks in advance.


Br,
Pinpe
# 5  
Old 06-18-2011
Here, an extra digit is getting added! I guess the user want the number to be intact and only that the last digit should have a period before it.

regards,
Ahamed
# 6  
Old 06-18-2011
yes ahamad,

You are right. I am sorry.
# 7  
Old 06-19-2011
Quote:
Originally Posted by guruprasadpr
Hi


Code:
$ cat a
111111111111
222222222222
333333333333


$ sed 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' a
website 11111111111.1.numbers.com
website 22222222222.2.numbers.com
website 33333333333.3.numbers.com


Guru.
This is PERFECT! Thanks dude! Smilie Smilie

Br,
Pinpe

---------- Post updated at 03:57 PM ---------- Previous update was at 03:10 PM ----------

Quote:
Originally Posted by guruprasadpr
Hi


Code:
$ cat a
111111111111
222222222222
333333333333


$ sed 's/\(.*\)\(.\)/website \1\.\2\.numbers.com/' a
website 11111111111.1.numbers.com
website 22222222222.2.numbers.com
website 33333333333.3.numbers.com


Guru.


Hi Guru,

Thank you very much for this elegant script. I just want to add more strings on the output file. I want to insert #!/bin/bash on top of the output file.

Desired Output File:
Code:
#!/bin/bash

website 11111111111.1.numbers.com
website 22222222222.2.numbers.com
website 33333333333.3.numbers.com


Br,
Pinpe
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