The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with output of find command being input to basename command... new_learner UNIX for Dummies Questions & Answers 2 12-14-2008 02:56 AM
awk/sed Command : Parse parameter file / send the lines to the ksh export command rajan_san Shell Programming and Scripting 4 11-06-2008 01:29 PM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 07:54 AM
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 09:12 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 09:26 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2009
shika123 shika123 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 1
using cut command

I am new to unix ... I have a file with name unixile.123761 I need to cut the extension from this file name? can u help me for this

i have tried like follows

copied the file lo one variable v

and then `echo $v | grep cut -d = -f 1`
  #2 (permalink)  
Old 06-18-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813

Code:
#!/bin/ksh
a=unixile.123761
firstpart=${a%%.*}
extension=${a##*.}

firstpart is now unixile, extension is 123761
  #3 (permalink)  
Old 06-18-2009
donisback donisback is offline
Registered User
  
 

Join Date: May 2009
Posts: 9
Hi jim,
could you please explain the command. I am new to Unix. I googled it and I could not find much information about curly braces.

Thanks,
Don
  #4 (permalink)  
Old 06-18-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
Those commands are used to split strings of characters into pieces.
You can also use cut, but it will have problems with a filename like mytarball.tar.gz

This page explains how to play with strings in bash (ksh has the same {} syntax for %, %%, #, and ##)
Manipulating Strings
  #5 (permalink)  
Old 06-18-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
The grep in your original post is surplus and will give syntax errors.
I think you meant:


Code:
v="unixile.123761"
w=`echo "$v" | cut -d\. -f1`
echo "$w"

unixile

  #6 (permalink)  
Old 06-18-2009
amitranjansahu's Avatar
amitranjansahu amitranjansahu is offline
Registered User
  
 

Join Date: Jan 2009
Location: Gurgaon,INDIA
Posts: 239
v="unixile.123761"
firstpart=`echo "$v" | cut -d '.' -f1`
extpart=`echo "$v" | cut -d '.' -f2`
  #7 (permalink)  
Old 06-18-2009
zvezdi zvezdi is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
for a in `ls`; do if [ $a != ${a%.*} ] ; then mv $a ${a%.*}; fi; done

write this in the shell when you are positioned in the directory where you want to make the changes; note that the command {a%.*} is non-greedy - that is the file 'this.is.my.file' will be renamed 'this.is.my', not just 'this'
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0