Help with renaming data content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with renaming data content
# 1  
Old 12-16-2011
Help with renaming data content

Input file:
Code:
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:
Code:
data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
 data4_result1
data4_result2
data5_result1
data5_result2
data5_result3
.
.
data60_result1

Hints:
1. Ascending the data and result naming from 1-(total number of different data)
eg. my input file have total 60 different data in this case
data21_a0_result1,data23_a1_result1,data43_a0_result1,data43_a1_result1,data43_a0_result3,data3_c1_r esult1...data9_c1_result1
(total got around 90 records but only 60 different data name such as data21,data23,data9,etc)
2. Keep those same data with new data naming
eg.
data43_a0_result1 data43_a1_result1 data43_a0_result3
all change to
data3_result1 data3_result2 data3_result3
3. Print out the data and result record only. Excluded those a0,a1,a0,etc.

Command that I tried:
Code:
[home@cpp_beginner]awk -F "_" '!a[$1]++{s++} {print "data"s"_"$3}' input_file.txt
data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
data4_result1
data4_result1
data5_result1
data5_result1
data5_result1
.
.
data60_result1

The command I tried fail to generate desired output result.

Thanks for any advice.
# 2  
Old 12-16-2011
Small fix:
Code:
awk -F "_" '!a[$1]++{s++} {print "data"s"_result"a[$1]}' input_file.txt

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 12-17-2011
Thanks bartus11, your awk code worked perfectly Smilie
Do you mind to explain why "a[$1]" will let the awk code recalculate each result from 1 once data is different?
Many thanks for advice.
# 4  
Old 12-17-2011
Code:
$
$ cat f44
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
$
$ perl -lne '/^data(\d+)_.*$/;
             if ($1 == $p) {$r++} else {$d++; $r=1}
             print "data",$d,"_result",$r;
             $p = $1
            ' f44
data1_result1
data2_result1
data3_result1
data3_result2
data3_result3
data4_result1
data4_result2
data5_result1
data5_result2
data5_result3
$
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Help with duplicate data content problem asking

Input file: A_69510335_ASD>aw 1199470 USA A_119571157_C>awe,QWEQE 113932840 USA C_34646666_qwe>TAWTT,G,TT 112736796 UK C_69510335_QW>T 1199470 USA D_70520237_WR>QEE,G 34459863 UK D_71380003_QWR>T 145418226 IK . Desired output: A_69510335_ASD>aw 1199470 USA... (1 Reply)
Discussion started by: perl_beginner
1 Replies

3. 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

4. Shell Programming and Scripting

Help with rename data content

Input file: data21_result1 data23_result1 data43_result1 data43_result2 data43_result3 data3_result1 . . data9_result1 Desired output data1_result1 data2_result1 data3_result1 data3_result2 data3_result3 data4_result1 (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. 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

6. Shell Programming and Scripting

Rearrangement of data content problem

Input data: >sample_1 WETYUPVLGK DGGHHHWETY QPERTTGGLO >sample_2 WRRTTOOLLP MKMKNJUTYE DLGLTTOC . . Desired output: >sample_1 WETYUP VLGKDG GHHHWE (8 Replies)
Discussion started by: patrick87
8 Replies

7. Shell Programming and Scripting

Renaming files based on data in a spreadsheet

I have a spreadsheet in a folder that looks like this: Sector1...Sector2...Sector3...Sector4...Sector5...Sector6...Sector7 SomeID....Title.......SomeID...SomeID....SomeID...SomeID....SomeID OtherID...MyTitle....SomeID...SomeID....SomeID...SomeID....SomeID... (7 Replies)
Discussion started by: Xterra
7 Replies

8. 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

9. Shell Programming and Scripting

Extract all the content after a specific data

My input: >seq_1 DSASSTRRARRRRTPRTPSLRSRRSDVTCS >seq_3 RMRLRRWRKSCSERS*RRSN >seq_8 RTTGLSERPRLPTTASRSISSRWTR >seq_10 NELPLEKGSLDSISIE >seq_9 PNQGDAREPQAHLPRRQGPRDRPLQAYA+ QVQHRRHDHSRTQH*LCRRRQREDCDRLHR >seq_4 DRGKGQAGCRRPQEGEALVRRCS>seq_6 FA*GLAAQDGEA*SGRG My output: Extract all... (22 Replies)
Discussion started by: patrick87
22 Replies

10. Shell Programming and Scripting

renaming multiple files with first line of content

Hi , I want to rename multiple files with their first line bar the first character + the extension .qual. For the example below the filename should read 7180000000987.qual. I have trawled through different threads for 2 days and I don't seem to find anything I can adopt for this task :confused: ... (7 Replies)
Discussion started by: Bruno
7 Replies
Login or Register to Ask a Question