LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-30-2012, 09:29 AM   #1
sunilsagar
LQ Newbie
 
Registered: Jul 2011
Posts: 29

Rep: Reputation: Disabled
help with cut command


Hello All,

I need help to change the path using cut. I tried lot of things, bit no luck.

Path = /a/b/c/d/e/f/g/
Output = /a/b/c/d/e/f

I want output as shown above. Please help

Thanks.
 
Old 01-30-2012, 09:38 AM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,814

Rep: Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001
Besides wanting to cut part of it off, are you looking to strip the last directory, and that's it? If so, you can simply use sed for this:
Code:
echo "/a/b/c/d/e/f/g/" | sed 's/.\{3\}$//'
Note that you need to use, change, modify, etc, to your liking's.

Cheers,

Josh
 
Old 01-30-2012, 09:42 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,564
Blog Entries: 54

Rep: Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928Reputation: 2928
'man cut': the "-d" and "-f" args or even simpler: VAR="/a/r/g/s"; dirname $VAR
 
Old 01-31-2012, 10:15 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
If the path is stored in a shell variable,then simple parameter substitution is all you need:

Code:
$ path='/a/b/c/d/e/f/g/'
$ echo "${path%/*/}"
/a/b/c/d/e/f
More shell string manipulations.
 
Old 01-31-2012, 10:44 AM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
(deleted)
' dirname ' was already refered by unSpawn :/

Last edited by Cedrik; 01-31-2012 at 10:48 AM.
 
Old 02-01-2012, 06:04 AM   #6
sunilsagar
LQ Newbie
 
Registered: Jul 2011
Posts: 29

Original Poster
Rep: Reputation: Disabled
thanks so much , there are so may ways .. din't knew that. all worked.
 
  


Reply

Tags
cut


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using cut command amjadask Linux - Server 1 03-04-2011 05:12 AM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 09:55 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
Cut Command Help!! fooforon Programming 2 02-05-2004 11:09 AM


All times are GMT -5. The time now is 05:24 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration