Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-30-2013
Registered User
 
Join Date: Jan 2013
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 05:30 AM.. Reason: Code tags
Sponsored Links
    #2  
Old 01-30-2013
zazzybob's Avatar
Registered Geek
 
Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,186
Thanks: 3
Thanked 23 Times in 22 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 01-30-2013
ningy's Avatar
Registered User
 
Join Date: May 2009
Location: Bangalore, India
Posts: 117
Thanks: 6
Thanked 17 Times in 16 Posts

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

    #4  
Old 01-30-2013
Registered User
 
Join Date: Jan 2013
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
that forum may be the best think that have happened to me 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 01-30-2013
Registered User
 
Join Date: Jan 2013
Location: IRAN/TEHRAN
Posts: 12
Thanks: 3
Thanked 1 Time in 1 Post
a great book : Unix programming environment by kernighan and rob pike
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12: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 03:57 PM
Deleting the Last value from a file theeights Shell Programming and Scripting 7 02-23-2010 12:50 AM
Help deleting a file shirtee UNIX for Dummies Questions & Answers 2 12-06-2007 10:43 AM
Deleting lines inside a file without opening the file toms Shell Programming and Scripting 3 09-24-2007 07:58 AM



All times are GMT -4. The time now is 12:31 PM.