Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Deleting file name

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-30-2013
gogok_bg gogok_bg is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 March 2013, 10:24 AM EDT
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Deleting file name

I need a way to remove all the file names with they are extension from a line of a document. For example:

I have doc named "gara" with the following content:


Code:
/media/gogo/6651-FEAB/Desktop/Desktop.jpg
/media/gogo/6651-FEAB/Desktop.pdf
/media/gogo/6651-FEAB/linux/logo1.jpg
/media/gogo/6651-FEAB/eks/HDD.Regenerator.2011-RES/INFOS/Proud Lion.doc

i need a way to remove the Desktop.jpg from the first line, Desktop.pdf from second line,

Code:
logo1.txt from 3 ed line and 
Proud Lion.doc from the 4 th line.

Thanks in advance.

Last edited by Scott; 01-30-2013 at 06:30 AM.. Reason: Code tags
Sponsored Links
    #2  
Old Unix and Linux 01-30-2013
zazzybob's Unix or Linux Image
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 25 Times in 23 Posts

Code:
$ sed 's!^\(.*\)/[^/]*$!\1/!' gogok.txt 
/media/gogo/6651-FEAB/Desktop/
/media/gogo/6651-FEAB/
/media/gogo/6651-FEAB/linux/
/media/gogo/6651-FEAB/eks/HDD.Regenerator.2011-RES/INFOS/

The Following User Says Thank You to zazzybob For This Useful Post:
gogok_bg (01-30-2013)
Sponsored Links
    #3  
Old Unix and Linux 01-30-2013
ningy's Unix or Linux Image
ningy ningy is offline
Registered User
 
Join Date: May 2009
Last Activity: 11 June 2014, 2:05 AM EDT
Location: Bangalore, India
Posts: 131
Thanks: 11
Thanked 17 Times in 16 Posts

Code:
awk -F"/" '{OFS="/";$NF="";print}' gara

    #4  
Old Unix and Linux 01-30-2013
gogok_bg gogok_bg is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 March 2013, 10:24 AM EDT
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
that forum may be the best think that have happened to me Linux BIG THX

ps: can you recommend any good places with tutorials for nubs lime me who are starting to with linux and trying to write screpts :> ?
Sponsored Links
    #5  
Old Unix and Linux 01-30-2013
mstafreshi mstafreshi is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 23 February 2016, 1:43 PM EST
Location: IRAN/TEHRAN
Posts: 18
Thanks: 3
Thanked 2 Times in 2 Posts
a great book : Unix programming environment by kernighan and rob pike
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting a pattern in UNIX without deleting the entire line Alyaa UNIX for Dummies Questions & Answers 15 03-15-2013 01:06 AM
awk - writing matching pattern to a new file and deleting it from the current file goddevil Shell Programming and Scripting 2 12-01-2012 04:57 PM
Deleting the Last value from a file theeights Shell Programming and Scripting 7 02-23-2010 01:50 AM
Help deleting a file shirtee UNIX for Dummies Questions & Answers 2 12-06-2007 11:43 AM
Deleting lines inside a file without opening the file toms Shell Programming and Scripting 3 09-24-2007 08:58 AM



All times are GMT -4. The time now is 03:40 AM.