help a newbie count!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help a newbie count!
# 1  
Old 08-08-2008
help a newbie count!

hello, I would really appreciate any help with this!
i have files in the format ####_*.dat

so like

2913_dsssf_sdfsdf_sddsf.dat
3208889423_lk3mnf_sdfe.dat

what im trying to do is extract the number from the start of the file (end of number will always be followed by _ ) and copy the file to multiple locations, incrementing the # by 1 for each new location

so
2913_dsssf_sdfsdf_sddsf.dat
=
/dir1/2914_dsssf_sdfsdf_sddsf.dat
/dir2/2915_dsssf_sdfsdf_sddsf.dat


3208889423_lk3mnf_sdfe.dat
=
/dir1/3208889424_lk3mnf_sdfe.dat
/dir2/3208889425_lk3mnf_sdfe.dat


huge thanks to anyone who can shed some light on this problem Smilie
# 2  
Old 08-08-2008
Code:
for i in *.dat
  do 
   x=${i%%_*}; y=${i#*_}; z=1
  
    for j in directory_list*
     do 
      cp -p $i $j/$(expr $x + $z)"_"$y
      z=$(expr $z + 1)
     done

done

Use echo first, instead of cp to make sure you have the expected output.
# 3  
Old 08-11-2008
Quote:
Originally Posted by rubin
Code:
for i in *.dat
  do 
   x=${i%%_*}; y=${i#*_}; z=1
  
    for j in directory_list*
     do 
      cp -p $i $j/$(expr $x + $z)"_"$y
      z=$(expr $z + 1)
     done

done

Use echo first, instead of cp to make sure you have the expected output.
about what i have colored on your code post. can you tell me what is it called?
if im correct, is some kind of automated string tokenizer, and i do have some good uses for that :P
# 4  
Old 08-11-2008
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

3. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

4. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

5. Shell Programming and Scripting

perl newbie . &&..programming newbie

Hi, I am new to programming and also to perl..But i know 'perl' can come to my rescue, But I am stuck at many places and need help..any small help is much appreciated... below is the description of what i intend to acheive with my script. I have a files named in this format... (13 Replies)
Discussion started by: xytiz
13 Replies

6. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

7. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

8. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

9. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies

10. Shell Programming and Scripting

Count help - newbie

I have a flat file sort by Phonenumber and Bigin call fileA.txt Phonnumber|Begin|Endca|D1|D2|Diff 4159061234|10:00|10:01|a1|a2|60 4159061234|10:00|10:06|b1|b2|360 4159061234|10:05|10:06|c1|c2|60 4159061234|10:12|10:15|d1|d2|180 3045678934|10:25|10:28|x1|x2|180... (11 Replies)
Discussion started by: britney
11 Replies
Login or Register to Ask a Question