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!

replacing ":" with "_" in a string using nawk...

Status
Not open for further replies.

buccaneers

Programmer
Jun 3, 2004
28
US
Hello Guru's,

I have following files
/SourceDir/File_Name:1:0224:2009
/SourceDir/File_Name:2:0224:2009

I want to move them to
/TargetDir/File_Name_1_0224_2009
/TargetDir/File_Name_2_0224_2009

Is there a way i can do this using nawk ?

Your feedback is greatly appreciable.

cheers,

LN
 
Hi

Like this ?
Code:
[blue]master #[/blue] echo '/SourceDir/File_Name:1:0224:2009
/SourceDir/File_Name:2:0224:2009
' | awk '{sub(/SourceDir/,"TargetDir");gsub(/:/,"_")}1'
/TargetDir/File_Name_1_0224_2009
/TargetDir/File_Name_2_0224_2009


Feherke.
 
Here is what i was looking for and got it.

h:w #find ./src -name "File_Name*" | sort | tail -2 | nawk '{t=$0; gsub(/:/,"_",t); print "mv "$0" "t}'
mv ./src/File_Name:0224:2009:1 ./src/File_Name_0224_2009_1
mv ./src/File_Name:0224:2009:2 ./src/File_Name_0224_2009_2

Cheers,

LN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top