Some questions - renaming duplicate names


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Some questions - renaming duplicate names
# 1  
Old 05-08-2009
Some questions - renaming duplicate names

I have a file that looks like this

2 4 10 500 tim9
5 8 14 700 tim9
3 5 15 432 john1
1 4 12 999 ellen2

So basically what i want to do is fine duplicate names on column 5 and rename it with an extention (i.e. tim9_1 and tim9_2).

so the output file will look like this

2 4 10 500 tim9_1
5 8 14 700 tim9_2
3 5 15 432 john1
1 4 12 999 ellen2

is this possible with awk?

Also I want to know the statistics on a column (like how many lines there are and also the sum of the values in that column)

eg.
1 3 6 7 3
2 4 7 3 2
1 4 7 4 2

So I want to know a awk command that will sum column 5 and tell me how many lines. In the example above, it will be sum = 7 and the total # of lines is 3.

Thanks for the help. The file that I have is huge so this would help a lot Smilie

Kyle
# 2  
Old 05-08-2009
Code:
nawk '$5 in a {$5=$5 "_" ++a[$5]}{a[$5];print}' myTimFile

Code:
nawk '{sum+=$5;fnr=FNR} END{printf("sum=%d total # of lines=%d\n", sum, fnr)}' mySumLinesFile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming the file names in a directory

Hi, I have about 60 files in a directory and need to rename those files. For example the file names are i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc) i_usa_phone_1_yymmdd.txt i_eng_phone_4_yymmdd.txt The new file names should be phone.txt phone_1.txt phone_4.txt I am... (4 Replies)
Discussion started by: naveed
4 Replies

2. Shell Programming and Scripting

Renaming File Names in a folder/Dir

Hi Team, I'm new to Unix shell scripting . I've the following requirement A folder contains the list of files with the following format ab.name.11.first ab.name.12.second ab.name.13.third ---------- I have to rename the above file to like below ... (6 Replies)
Discussion started by: smile689
6 Replies

3. UNIX for Dummies Questions & Answers

Renaming files with weird names

I have hundreds of files with weird names, something like this: I was wondering how can I rename them all keeping the sampleid and the last extension, something like this: Any help will be greatly appreciated. (5 Replies)
Discussion started by: Xterra
5 Replies

4. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

5. UNIX for Dummies Questions & Answers

Renaming files in one file from names in other

Hi Guys, I have a small problem of renaming multiple files. For example I have names of a set of files in one directory like K2_34625-34675 K7_988963-988983 K12_773882-7734102 and the other set corresponding to the same is U_P_321_9_3_11.ab1 U_P_322_9_3_11.ab1 U_P_323_9_3_11.ab1 Now... (23 Replies)
Discussion started by: pawannoel
23 Replies

6. Shell Programming and Scripting

Renaming file names

I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (2 Replies)
Discussion started by: vpv0002
2 Replies

7. Shell Programming and Scripting

renaming files from an array of names

I haven’t used Unix in over 25 years … and so I am at a loss for something that should be very simple. I have a lot of jpeg files (i.jpg) of students in a yearbook.. I also have an array name(i) of their names. I need to rename each “i.jpg” to “name(i).jpg”. I believe the ksh script... (11 Replies)
Discussion started by: chuckmg
11 Replies

8. UNIX for Dummies Questions & Answers

Renaming duplicate files in a loop

Hello, I have a bunch of files whose names start with 'xx' The first line of each file looks something like: a|...|...|...|... , ... In order to rename all of these files to whatever's between the 4th | and the comma (in the first line of that particular file) , I have been using: for... (2 Replies)
Discussion started by: juliette salexa
2 Replies

9. Shell Programming and Scripting

duplicate index names renamed

Hello everyone ! Please have a minute and see if you know how to script this I have a file like this: "create table .... ... create index n112 on ... ... create table ... .... create index n113 on... ... create table ... create index n112 on ...! duplicate ... (1 Reply)
Discussion started by: sotoc79
1 Replies

10. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies
Login or Register to Ask a Question