Sponsored Content
Full Discussion: ID generation in sequence
Top Forums Shell Programming and Scripting ID generation in sequence Post 302370982 by radoulov on Friday 13th of November 2009 04:38:59 AM
Old 11-13-2009
Quote:
Originally Posted by summer_cherry
Code:
while(<DATA>){
    s/(?<=<id>)(?=<id>)/$./e;
    print;
}
__DATA__
<data><id><id><name>a</name><addr>aaa</addr><phnumb>3456</phnumb><state>ca</state><city>ny</city></data>
<data><id><id><name>b</name><addr>bbb</addr><phnumb>4567</phnumb><state>la</state><city>nj</city></data>
<data><id><id><name>c</name><addr>ccc</addr><phnumb>5678</phnumb><state>nv</state><city></city></data>
<data><id><id><name>d</name><addr>ddd</addr><phnumb>6789</phnumb><state>oh</state><city></city></data>
<data><id><id><name>e</name><addr>eee</addr><phnumb>7890</phnumb><state>al</state><city></city></data>

Yes, this should work if every line contains the id tag and you can even omit the e modifier.

---------- Post updated at 10:38 AM ---------- Previous update was at 10:35 AM ----------

Quote:
Originally Posted by Sgiri1
[...]
hi error is thrown when i try to execute the below code
perl -pe'
s/<id></id>/"<id>".++$c."</id>"/e
' infile

[...]
Code:
% cat infile
<data><id></id><name></name><city></city></data>@@#<data><id></id><name></name><city></city></data>@@#<data><id></id><name></name><city></city></data>@@#<data><id></id><name></name><city></city></data>@@#

Code:
% perl -pe' 
  s|<id></id>|"<id>".++$c."</id>"|ge
  ' infile
<data><id>1</id><name></name><city></city></data>@@#<data><id>2</id><name></name><city></city></data>@@#<data><id>3</id><name></name><city></city></data>@@#<data><id>4</id><name></name><city></city></data>@@#

 

9 More Discussions You Might Find Interesting

1. Programming

Shellcode Generation using C

Hi, I was just learning about buffer overflow attacks... I was curious as to how to generate a simple shellcode. I've written two codes - One is the typical program that has a vulnerability inside and the other is the shellcode. main program: void test(); int main() { test(); ... (2 Replies)
Discussion started by: Legend986
2 Replies

2. Shell Programming and Scripting

Sequence number generation on a key column

Hi Folks, Can you help me with this issue: I have to generate the numbers say from 1001 for each record in a file based on a key field, the catch is the generated number should be unique based on key column. (EMP_NUMBER) Example: Input File: EMP_NUMBER EMP_NAME 8908 ... (6 Replies)
Discussion started by: sbasetty
6 Replies

3. Shell Programming and Scripting

Graph generation

How can I generate graphs using perl in unix solaris environment? Please suggest. (2 Replies)
Discussion started by: wadhwa.pooja
2 Replies

4. Shell Programming and Scripting

Help with excelsheet generation

Hi All, i have around 50 queries in sybase. We have a requirement where we need to write a unix script, which execute the query one by one & generate the excel sheet & send it to user. I have completed half of the part, where i am executing query one by one & putting the result into a .txt... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies

5. Shell Programming and Scripting

Config Generation

I'm looking for good ways to handle config generation. I have been rolling my own for a few years now, but I'm wondering if there is a better way and would like to get some advice from anyone who has any ideas or experience in doing this. Here are some things I want to achieve in generating... (1 Reply)
Discussion started by: humbletech99
1 Replies

6. Shell Programming and Scripting

Character generation

I need a (bash) script to echo to the screen all possible 4 character hex combinations of: A-F, 0-9. I beleive there are 65,535 approx combos. Output something like this: 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A ... ... FFFE FFFF (6 Replies)
Discussion started by: ajp7701
6 Replies

7. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

8. Shell Programming and Scripting

Sequence generation in shell

Hi, I am using the nested for loops to generate the sequence , taking start and end sequence number input from test.txt (sample content mentioned below). Also , can I print the rest of columns as well with sequence number into the same file. for i in `cat test.txt|cut -d"," -f7` do ... (8 Replies)
Discussion started by: tushar.modgil
8 Replies

9. Shell Programming and Scripting

Help with file generation

Dear all Hope you are doing good. I've requirement where in I need to generate a file containing set of SQLs as per the inputs. My script flow is like reading few parameters using read command to read input to script and process the inputs. However at one of the input, my script has to... (3 Replies)
Discussion started by: tenderfoot
3 Replies
All times are GMT -4. The time now is 08:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy