Prev: Do some simple addition operations under bash by using expr
Next: Man vs. Info: documenting the software
From: Melvin on 2 Feb 2010 01:07 Hi, I want my shell to input a file using $argv[1] and cut the .gz part in it.i.e. if the input file name taken by $argv[1] is xyz.gz, I want $argv[1] to be assigned as xyz. How can I do this using cut command. Thanks in advance Unix Baby
From: Medernach on 2 Feb 2010 02:58 Melvin wrote: > Hi, > > I want my shell to input a file using $argv[1] and cut the .gz part > in it.i.e. if the input file name taken by $argv[1] is xyz.gz, I want > $argv[1] to be assigned as xyz. > > How can I do this using cut command. > > Thanks in advance > Unix Baby You could use the basename command like this: # basename a.gz .gz a Regards, -- Medernach
From: Chris F.A. Johnson on 2 Feb 2010 03:34 On 2010-02-02, Melvin wrote: > > I want my shell to input a file using $argv[1] and cut the .gz part > in it.i.e. if the input file name taken by $argv[1] is xyz.gz, I want > $argv[1] to be assigned as xyz. Where does $argv[1] come from? > How can I do this using cut command. If the filename is in a variable, use parameter expansion: file=xyz.gz base=${file%.*} -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: Melvin on 2 Feb 2010 03:58
On Feb 2, 12:58 pm, Medernach <medern...(a)clermont.in2p3.fr> wrote: > Melvin wrote: > > Hi, > > > I want my shell to input a file using $argv[1] and cut the .gz part > > in it.i.e. if the input file name taken by $argv[1] is xyz.gz, I want > > $argv[1] to be assigned as xyz. > > > How can I do this using cut command. > > > Thanks in advance > > Unix Baby > > You could use the basename command like this: > # basename a.gz .gz > a > > Regards, > -- > Medernach Thanku Medernach. Perfect Solution!!! |