Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help removing underscores at the end of a name 2

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi there!

I have the following two files:
cb_mt_oligocene_marker_Zap__________________________________
mbh_amigo_area_senonian_base_fan_1__________________________
mbh_amigo_area_senonian_top_fan_1___________________________
mbh_fulls_mid_tertiary_unc_Zap______________________________
mbh_intra_albian_Zap________________________________________
mbh_late_k_marker_1_Zap_merged______________________________
mbh_rift_grid_from_pseis____________________________________
mbh_senonian________________________________________________
mbh_senonian_top_slide______________________________________
mbh_tertiary_structural_marker_Zap_interpolated_____________
mbh_top_mounded_prograding_interval_Zap_____________________
mg_992_zap__________________________________________________
wb_Zap_interpolated_________________________________________

and

cb_mt_oligocene_marker_ZAP
mbh_amigo_area_senonian_base_fan_1
mbh_amigo_area_senonian_top_fan_1
mbh_fulls_mid_tertiary_unc_Zap
mbh_intra_albian_Zap
mbh_late_k_marker_1_Zap_merged
mbh_rift_grid_from_pseis
mbh_senonian
mbh_senonian_top_slide
mbh_tertiary_structural_marker_Zap_interpolated
mbh_top_mounded_prograding_interval_Zap
mg_992_zap
wb_Zap_interpolated

The difference between the two files is that in the first one the name is padded with underscores up to 60 characters. Can someone please help me with an awk script that would go from one to the other (i.e. remove/add underscores), the trick being that there are underscores also in the middle of the name.

Thanks!
 
It's easier with sed...
[tt]
cat file1|sed 's/_*$//' > file2[/tt]
 
thanks Ygor, what about going the other way?
 
Sorry, this is the awk forum so my first post should be...
[tt]
awk '{a=$0;sub("_*$","",a);print a}' file1 > file2
[/tt]
So, to go the other way...
[tt]
awk '{a=sprintf("%-60s",$0);gsub(" ","_",a);print a}' file2 > file3
[/tt]
 
and even easier [avoiding a UUOC]:

sed 's/_*$//' file1 > file2

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thank you for getting rid of the pipe from cat, aaargh!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top