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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using sed to cut file names

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, sorry to be asking you again, but I want to cut the file names extensions or main part. is sed suitable for this? ie i want to cut fred.doc to fred, or doc
i have tried
echo $file | sed 's/*\.//' and
echo $file | sed 's/\.*//'
but it wont work, any ideas?
cheers, brian
 

Hi, brian_walker!

Please, try this awk solution:

awk 'BEGIN { print substr(ARGV[1],1,index(ARGV[1],".") - 1) }' argument


Instead of argument put your string. This awk program cuts any characters from . to end of string.

Bye!

KP.
 
Brian

You could also try :

echo $file | cut -d'.' -f1 (for file name)
echo $file | cut -d'.' -f2 (for extention)

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top