Help with rename data content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with rename data content
# 1  
Old 10-06-2011
Help with rename data content

Input file:
Code:
data21_result1
data23_result1
data43_result1
data43_result2
data43_result3
data3_result1
.
.
data9_result1

Desired output
Code:
data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
data4_result1
.
.
data59_result1

Rule to rename:
1. Ascending the data naming from 1-(total number of different data)
eg. my input file have total 59 different data in this case
data21_result1 data23_result1 data43_result1 data43_result2 data43_result3 data3_result1 ... data9_result1 (total got around 90 but only 59 different data name such as data21,data23,data9,etc)
2. Keep those same data with new data naming
eg.
data43_result1 data43_result2 data43_result3
all change to
data3_result1 data3_result2 data3_result3

Thanks for any advice

---------- Post updated 10-06-11 at 02:07 AM ---------- Previous update was 10-05-11 at 11:17 PM ----------

Does anybody got idea regarding my question?
Thanks first !
# 2  
Old 10-06-2011
Code:
$ cat f1
data21_result1
data23_result1
data43_result1
data43_result2
data43_result3
data3_result1

Code:
$ nawk -F_ '{print "data" (++C[$2]) FS $2}' f1
data1_result1
data2_result1
data3_result1
data1_result2
data1_result3
data4_result1

Code:
$ nawk -F_ '{print "mv " $0 " data" (++C[$2]) FS $2}' f1
mv data21_result1 data1_result1
mv data23_result1 data2_result1
mv data43_result1 data3_result1
mv data43_result2 data1_result2
mv data43_result3 data1_result3
mv data3_result1 data4_result1

You can then redirect into a file and check that it rename things as you expect and if ok then run it

Last edited by ctsgnb; 10-06-2011 at 10:01 AM..
# 3  
Old 10-06-2011
Code:
awk -F _ '!a[$1]++{s++} {print "data" s FS $2}' infile

data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
data4_result1
data5_result1

This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 10-07-2011
Quote:
Originally Posted by perl_beginner
Input file:
Code:
data21_result1
data23_result1
data43_result1
data43_result2
data43_result3
data3_result1
.
.
data9_result1

Desired output
Code:
data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
data4_result1
.
.
data59_result1

Rule to rename:
1. Ascending the data naming from 1-(total number of different data)
eg. my input file have total 59 different data in this case
data21_result1 data23_result1 data43_result1 data43_result2 data43_result3 data3_result1 ... data9_result1 (total got around 90 but only 59 different data name such as data21,data23,data9,etc)
2. Keep those same data with new data naming
eg.
data43_result1 data43_result2 data43_result3
all change to
data3_result1 data3_result2 data3_result3
...
Here's a Perl solution:

Code:
$
$ cat f32
data21_result1
data23_result1
data43_result1
data43_result2
data43_result3
data3_result1
data4_result1
data5_result1
data6_result1
data6_result1
data7_result1
data8_result1
data8_result1
data8_result1
data8_result1
data8_result1
data9_result1
$
$ perl -lne '/^(.*?)(\d+)(_.*)$/; print $1, $2==$p ? $i : ++$i, $3; $p=$2' f32
data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
data4_result1
data5_result1
data6_result1
data7_result1
data7_result1
data8_result1
data9_result1
data9_result1
data9_result1
data9_result1
data9_result1
data10_result1
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File and file content string rename

We have around 1000 scripts in a specific folder like mcx001.txt, mcx002.txt, mcx999.txt, mce001.txt etc We need to rename those files where 3rd character is "x" and should be replaced by "y". So files should be renamed to mcy001.txt, mcy002.txt, mcy999.txt Also, mcx001.txt have content... (5 Replies)
Discussion started by: vedanta
5 Replies

2. Shell Programming and Scripting

awk : split file and rename and save in path according to content

Hello, I'm using Windows 7 ; sed, awk and gnuwin32 are installed. I have a big text file I need to manipulate. In short, I will have to split it in thousands of short files, then rename and save in a folder which name is based upon filename. Here is a snippet of my big input.txt file (this... (4 Replies)
Discussion started by: sellig
4 Replies

3. Shell Programming and Scripting

Help with transpose data content

Hi, Below is my input file: c116_g1_i1 -,-,-,+ c118_g2_i1 +,+ c118_g3_i1 + c120_g1_i1 +,+,+,+ . . Desired Output File c116_g1_i1 - c116_g1_i1 - c116_g1_i1 - c116_g1_i1 + c118_g2_i1 + c118_g2_i1 + (3 Replies)
Discussion started by: perl_beginner
3 Replies

4. Shell Programming and Scripting

Help with renaming data content

Input file: data21_a0_result1 data23_a1_result1 data43_a0_result1 data43_a1_result2 data43_a0_result3 data3_c0_result1 data3_c1_result1 data423_c0_result1 data423_c1_result1 data423_a0_result1 . . data9_c1_result1 Desired output file: data1_result1 data2_result1 (3 Replies)
Discussion started by: cpp_beginner
3 Replies

5. Shell Programming and Scripting

Help with replace data content

Format of one input file: # >length=1 seq program data 909 1992 seq program record 909 1190 Desired output result: # >length=1 length=1 program data 909 1992 length=1 program record 909 1190 I wanna to replace all the column 1 content (exclude the content start with "#") with the... (5 Replies)
Discussion started by: cpp_beginner
5 Replies

6. Shell Programming and Scripting

Help with reformat data content

input file: hsa-miR-4726-5p Score hsa-miR-483-5p Score hsa-miR-125b-2* Score hsa-miR-4492 hsa-miR-4508 hsa-miR-4486 Score Desired output file: hsa-miR-4726-5p Score hsa-miR-483-5p Score hsa-miR-125b-2* Score hsa-miR-4492 hsa-miR-4508 hsa-miR-4486 Score ... (6 Replies)
Discussion started by: perl_beginner
6 Replies

7. Shell Programming and Scripting

Help with rename header content based on reference file problem

I got long list of reference file >data_tmp_number_22 >data_tmp_number_12 >data_tmp_number_20 . . Input file: >sample_data_1 Math, 5, USA, tmp SDFEWRWERWERWRWER FSFDSFSDFSDGSDGSD >sample_data_2 Math, 15, UK, tmp FDSFSDFF >sample_data_3 Math, 50, USA, tmp ARQERREQR . . Desired... (7 Replies)
Discussion started by: perl_beginner
7 Replies

8. Shell Programming and Scripting

Extract specific content from data and rename its header problem asking

Input file 1: >pattern_5 GAATTCGTTCATGTAGGTTGASDASFGDSGRTYRYGHDGSDFGSDGGDSGSDGSDFGSDF ATTTAATTATGATTCATACGTCATATGTTATTATTCAATCGTATAAAATTATGTGACCTT SDFSDGSDFKSDAFLKJASLFJASKLFSJAKJFHASJKFHASJKFHASJKFHSJAKFHAW >pattern_1 AAGTCTTAAGATATCACCGTCGATTAGGTTTATACAGCTTTTGTGTTATTTAAATTTGAC... (10 Replies)
Discussion started by: patrick87
10 Replies

9. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

10. Shell Programming and Scripting

Find out the match data content?!

Hi, Long list of Input file1 content: 1285_t 4860_i 4817_v 8288_c 9626_a . . . Long list of Input file2 content: 1285_t chris germany 8288_c steve england 9626_a dave swiss 9260_s stephanie denmark . . . (14 Replies)
Discussion started by: patrick87
14 Replies
Login or Register to Ask a Question