LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-22-2006, 04:37 PM   #1
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 42
sed command not working right


Didn't know of a better title for the thread.. But anyways.. I am using the command sed to remove all periods from a file name. But the result is that it removes the first character of the file name...Here is an example


sh-3.00$ echo filename.text | sed 's/.//g'

sh-3.00$ echo filename.text | sed 's/.//'
ilename.text
sh-3.00$ uname -a
Linux 2.4.31 #6 Sun Jun 5 19:04:47 PDT 2005 i686 unknown unknown GNU/Linux
sh-3.00$


In the first example with the global flag(g) it puts spaces in for every character, in the second example without the global flag it jst removes the first character..


Whats up with this? Im pretty sure im using sed right, how can I just remove the periods from the filenames?
 
Old 04-22-2006, 04:56 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
The . is an expression that matches a single character. If you want to match a literal '.' you need to escape it. The following returns filenametxtext:
Code:
echo filename.txt.ext | sed -e 's/\.//g'
I assume you have the sed expression wrapped in a loop that mv's files?
 
Old 04-22-2006, 05:27 PM   #3
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Original Poster
Rep: Reputation: 42
that worked. Thanks.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command Kalyani1 Linux - Software 28 12-07-2005 11:48 AM
sed command rharris72 Programming 6 11-20-2005 08:26 PM
Sed command in file not working lbauer Programming 5 04-06-2005 12:31 PM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM
sed Command linuxdev Linux - Newbie 3 02-09-2004 11:27 AM


All times are GMT -5. The time now is 01:43 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