LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-15-2004, 06:40 PM   #1
aurelio26
Member
 
Registered: Dec 2003
Location: CANADA
Distribution: Fedora
Posts: 40

Rep: Reputation: 15
remove "-" (dash) from file


I want to remove - (dash) from file using sed and replace with empty space.

I tried this command, but nothing happend.

sed -e 's/\-/ /' file > file2

Help !!!
 
Old 09-15-2004, 07:14 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Is the - in the file, or in the file-name? :)

If it's in the name you should keep the -
and start replacing all your spaces with
something more sensible, like - or _ ;)


Cheers,
Tink
 
Old 09-15-2004, 07:26 PM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Are you sure nothing happened? file2 was created, right? I'll bet if you look closely, you'll find the first - on each line was changed to a space in file2. You need to put a 'g' at the end to tell sed to do the replace everywhere, instead of just the first match it finds. So:

sed -e 's/-/ /g' file > file2

should do what you want (the extra backslash you added isn't necessary, but won't hurt either).
 
Old 09-15-2004, 07:30 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Oo, never thought you might have meant the filename instead of the contents. sed works on what's in the file, not the filename... although you could use sed to accomplish that:

mv my-big-long-file "`echo my-big-long-file | sed -e 's/-/ /g'`"

but it would be easier to use the rename command in that case. Check 'man rename'.
 
Old 09-16-2004, 11:32 AM   #5
aurelio26
Member
 
Registered: Dec 2003
Location: CANADA
Distribution: Fedora
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks for response guys.

g at the end of sed line solved problem.
File was so huge that each time I did
sed -e 's/\-/ /' file1 > file2

I couldn't notice that only first of them changed from - to space.

sed -e 's/\-/ /g' file1 > file2
saved my vacation!!!!!!

Thanks CroMagnon!!!
 
  


Reply


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
how to remove the file "-rf"? codec Linux - Software 6 03-12-2005 12:03 PM
how can i remove this file "-gxxxx" zameer_india Linux - Newbie 6 01-29-2005 02:25 AM
remove a file that has a " | " in it's name disorderly Linux - Security 3 09-27-2004 01:24 PM
How to remove a file called: "-be" zepplin611 AIX 7 08-21-2004 03:37 PM
remove "special" text out of a file tearinox Linux - General 1 03-15-2004 08:43 PM


All times are GMT -5. The time now is 09:07 PM.

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