Visit Our UNIX and Linux User Community


Creating a sequence of numbers in a line for 1000 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a sequence of numbers in a line for 1000 files
# 1  
Old 05-14-2016
Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this:

Code:
aasdsaffsc23
scdsfsddvf46567
mionome0001.pdb
asdsdvcxvds
dsfdvcvc2324w

What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have :
nomefile0001.txt that must have the line mionome0001.pdb
nomefile0002.txt that must have the line mionome0002.pdb
and so on up to nomefile1000.txt with the line mionome1000.pdb

Can you give me some advice ? Maybe I could use sed ... but how ??? Thanks a lot to everyone



Moderator's Comments:
Mod Comment Please use code tags for data as well as required by forum rules!

Last edited by RudiC; 05-14-2016 at 02:56 PM.. Reason: Added code tags.
# 2  
Old 05-14-2016
Not too clear. Do you want 1000 output files containing
Code:
aasdsaffsc23
scdsfsddvf46567
mionome0001.pdb  ( - mionome1000.pdb)
asdsdvcxvds
dsfdvcvc2324w

, i.e have the same contents except for the third line that will be numbered ascendingly (guessing that "myname" equals "mionome")?

Last edited by RudiC; 05-14-2016 at 03:07 PM..
# 3  
Old 05-14-2016
is correct, the file must have the same content except for that line
# 4  
Old 05-14-2016
You mentioned mionome0001.pdb. What happens with the other lines in the file?
# 5  
Old 05-14-2016
i want to change only the line mionome0001.pdb
the other lines are unchanged in all the 1000 files

Last edited by Don Cragun; 05-14-2016 at 04:37 PM.. Reason: Add ICODE tags.
# 6  
Old 05-14-2016
Try
Code:
awk ' 
        {P[NR] = $1
         if (/mionome/) IX = NR
        }
END     {for (i=1; i<=CNT; i++) {T = sprintf ("%04d.", i)
                                 FN = "nomefile" T "txt" 
                                 sub (/[0-9]+\./, T, P[IX])
                                 for (j=1; j<=NR; j++) print P[j] > FN
                                 close (FN) 
                                }
        }
' CNT=1000 file

# 7  
Old 05-14-2016
my real file is this:
Code:
outlev 1
parameter_file AD4.1_bound.dat
intelec
seed pid time
ligand_types A C OA N NA S SA HD F Cl Br
fld 3dct_apo_box50.maps.fld
map 3dct_apo_box50.A.map
map 3dct_apo_box50.C.map
map 3dct_apo_box50.OA.map
map 3dct_apo_box50.N.map
map 3dct_apo_box50.NA.map
map 3dct_apo_box50.S.map
map 3dct_apo_box50.SA.map
map 3dct_apo_box50.HD.map
map 3dct_apo_box50.F.map
map 3dct_apo_box50.Cl.map
map 3dct_apo_box50.Br.map
elecmap 3dct_apo_box50.e.map
desolvmap 3dct_apo_box50.d.map
move 4e4k_lig.pdbqt
about 20.088 64.795 18.258
tran0 random
quat0 random
dihe0 random
tstep 2.0
qstep 50.0
dstep 50.0
rmstol 2.0
extnrg 1000.0
e0max 0.0 10000
ga_pop_size 300
ga_num_evals 5000000
ga_num_generations 27000
ga_elitism 1
ga_mutation_rate 0.02
ga_crossover_rate 0.8
ga_window_size 10
ga_cauchy_alpha 0.0
ga_cauchy_beta 1.0
set_ga
sw_max_its 300
sw_max_succ 4
sw_max_fail 4
sw_rho 1.0
sw_lb_rho 0.01
ls_search_freq 0.06
set_sw1
ga_run 1000
analysis

i want to change only 4e4k_lig.pdbqt in 4e4k_lig0001.pdbqt ecc ecc for all 1000 files.

with your command, the result is this:

Code:
outlev
parameter_file
intelec
seed
ligand_types
fld
map
map
map
map
map
map
map
map
map
map
map
elecmap
desolvmap
move0051.4k_lig.pdbqt
about
tran0
quat0
dihe0
tstep
qstep
dstep
rmstol
extnrg
e0max
ga_pop_size
ga_num_evals
ga_num_generations
ga_elitism
ga_mutation_rate
ga_crossover_rate
ga_window_size
ga_cauchy_alpha
ga_cauchy_beta
set_ga
sw_max_its
sw_max_succ
sw_max_fail
sw_rho
sw_lb_rho
ls_search_freq
set_sw1
ga_run
analysis


Last edited by Don Cragun; 05-14-2016 at 04:39 PM.. Reason: Add CODE and ICODE tags.

Previous Thread | Next Thread
Test Your Knowledge in Computers #420
Difficulty: Medium
JavaScript supports much of the structured programming syntax from C (e.g., if statements, while loops, switch statements, do while loops, etc.).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating sequence number as per records

Hi, I have a file source as below. OL|10031|Day|Black|Midi|Good|Value|P01|P07 OL|10031|Day|Black|Short|Good|Value|P01|P07 I need to create a file form the above data as below logic 1. take the first line 2. create a file say inclusion1 as below from the first line OL,10031,1,Day... (8 Replies)
Discussion started by: bhaski2012
8 Replies

2. Shell Programming and Scripting

Script to generate sequence of numbers

I need awk script to generate part number sequencing based on data in multiple columns like below Input File --------- Col A|Col B|Col C| 1|a|x| 2|b|y| |c|z| | |m| | |n| And out put should be like 1ax 1ay 1az 1am 1an 1bx 1by (6 Replies)
Discussion started by: aramacha
6 Replies

3. UNIX for Dummies Questions & Answers

Replace lines of two files by the corresponding line numbers.

I want to replace lines. The files 1 are (separated by \t) Gm01 phytozome9_0 three_prime_UTR 70641 70759 . - . ID=PAC:26323927.three_prime_UTR.1;Parent=PAC:26323927;pacid=26323927 Gm01 phytozome9_0 three_prime_UTR 90230 90692 . - . ... (1 Reply)
Discussion started by: grace_shen
1 Replies

4. Shell Programming and Scripting

Adding a line to 1000's of files right after x amt of characters.

I am trying to add a single line of text to every file in a particular folder. There are thousands of files in the folder. Each file contains this same start of the first line: {d "%w- %d %m-, %Y - %T"} <some message here> with the rest of the text following the second curly bracket... (10 Replies)
Discussion started by: dlundwall
10 Replies

5. Shell Programming and Scripting

Perl verify if numbers in a column of a file are in sequence

I am just a newbie to perl scripting. I need help with listing of hexadecimal numbers in a column as follows. INPUT FIle: 08AF ship steel 08B0 ship steel 08B1 ship steel 08B2 flight docs 08B3 flight docs 08B4 flight docs 08B5 flight docs 08B6 flight decl ... (3 Replies)
Discussion started by: dynamax
3 Replies

6. Shell Programming and Scripting

Need to find the gap in the sequence of numbers

Hi Guys, I have a file with numbers in sequence. The sequence have been broken somewhere.. I need to find out at which number the sequence has been broken... For an example, consider this sequence, it needs to give me output as 4 (as 5 is missing) and 6(as 7 is missing) Thanks for... (3 Replies)
Discussion started by: mac4rfree
3 Replies

7. Shell Programming and Scripting

Creating 1000 files using a script

I would like to write a script that would create 1000 files like clm0001.txt to clm1000.txt. All the files would contain the same contents. How do I achieve this using a script?Please help. (2 Replies)
Discussion started by: ggayathri
2 Replies

8. Shell Programming and Scripting

Random numbers from 0 to 1000

Hello All, I want to make a simple script which generate random number from 0 to 1000. and simply display it. Plz HELP!!!!!! Regards, Waqas Ahmed (2 Replies)
Discussion started by: wakhan
2 Replies

9. UNIX for Dummies Questions & Answers

creating sequence numbers in unix

Hi, Is there a way to create sequence numbers in unix i have a set of batches(which contain records) and i want to assign a number to every batch. how can i do that? (1 Reply)
Discussion started by: dnat
1 Replies

10. UNIX for Dummies Questions & Answers

how can i isolate the random sequence of numbers using awk?

as you can see there is a delimiter after c8 "::". Awk sees the rest as fields because it doesn't recognize spaces and tabs as delimiters. So i am basically looking to isolate 20030003ba13f6cc. Can anyone help? c8::20030003ba13f6cc disk connected configured unknown (2 Replies)
Discussion started by: rcon1
2 Replies

Featured Tech Videos