Dynamic number to replace with line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dynamic number to replace with line
# 8  
Old 07-30-2013
Thanks for reply

What I did

Code:
$ sed s/'# at '/'insert into test.dummy(id) values ("'/ dynamic

COMMIT
insert into test.dummy(id) values ("2345

insert into test.dummy(id) values ("2346
COMMIT
insert into test.dummy(id) values ("2478
update one
insert into test.dummy(id) values ("2489

The Last thing I want to add ");" in the Last of every line of insert command

How can this be done ...
# 9  
Old 07-30-2013
If you look at my awk, they do just what you like.
Post the complete file dynamic
# 10  
Old 07-30-2013
I Have attached the file as dynamic.txt

In This there are

Code:
# at 4
# at 98
# at 211

Want to replace with as below for all
Code:
insert into test.counter(id) values(4);
insert into test.counter(id) values(98);
insert into test.counter(id) values(211);

rest thing remain same
# 11  
Old 07-30-2013
Code:
perl -pe 's/# at (\d+)/insert into test.dummy(id) values (\"\1\")/g' dynamic

# 12  
Old 07-30-2013
Quote:
Originally Posted by rajamadhavan
Code:
perl -pe 's/# at (\d+)/insert into test.dummy(id) values (\"\1\")/g' dynamic


Thanks This works for me
# 13  
Old 07-30-2013
Quote:
Only the numbers are below commit should change
perl -pe 's/# at (\d+)/insert into test.dummy(id) values (\"\1\")/g' dynamic
This perl replaces all # at lines, but you stated only lines below commit???

Same solution using awk
Code:
awk '/# at/ {$0="insert into test.counter(id) values("$3");"} 1' dynamic.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a number in the last line of a delimited file.

Hi all, I am fairly new to UNIX and I was wondering if you could provide me with some help! Lets say i have a file as below : Line 1 Line 2 Line 3 ABC|12|4|2 Now the number 4 in bold, this number will represent the number of row there is in the file excluding the header and footer... (10 Replies)
Discussion started by: Stinza
10 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

Replace a field with line number in file

I am working on a script to convert bank data to a csv file. I have the format done - columns etc. The final piece of the puzzle is to change the second field (after the R) of every line to reflect its' line number in the file. I am stumped. I can use awk on each line but need help looping through... (9 Replies)
Discussion started by: Melah Gindi
9 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

Replace first number of each line in a file with another number

Hi, I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@, for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies

6. Shell Programming and Scripting

replace line starting with not a number

Dear users, I have a file like this: geometry,geometry_vertex_count,Id,strnum,platecode,datatype,dtnum,refnum,appearance,disappeara,color,geogdesc,datatype_ft_style,import_notes "<LineString><coordinates>-130.6539,51.5103,0 -130.7708,51.6287,0 -130.8356,51.6832,0 -130.9211,51.7772,0... (5 Replies)
Discussion started by: Gery
5 Replies

7. Shell Programming and Scripting

replace blank line number

hlow all i need help how can i replace blank number with awk input.txt 300::|355264313178490 301::|358814003239510 302::|358316038113400 303::|357954002633660 304::|354072040694090 305::|356956015214190 306::|352943020525180 307::|359574033836610 308::|381810990023580 so will be like... (4 Replies)
Discussion started by: zvtral
4 Replies

8. Shell Programming and Scripting

Replace 2nd column for each line in a csv file with fixed string+random number

Hi experts, My csv file looks like this U;cake;michael;temp;;;; U;bread;john;temp;;;; U;cocktails;sarah;temp;;;; I'd like to change the value fo 2nd column to cf+random number , which will look maybe something like this U;cf20187;michael;temp;;;; U;cf8926;john;temp;;;;... (7 Replies)
Discussion started by: tententen
7 Replies

9. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

10. UNIX for Dummies Questions & Answers

Replace line number 2 with another line

Hi, How can i replace second Line of a file with another line. The whole 2nd line should be replaced with new line. Please let me know the solution. Thanks, Sri (1 Reply)
Discussion started by: srilaxmi
1 Replies
Login or Register to Ask a Question