LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-11-2011, 12:54 PM   #1
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Rep: Reputation: 10
Replaces Empty spaces by underscore.


Hi all,

my requirement is i need to copy mail subject to a text file and create one directory from the name of subject.

my MAIL subject is like this :
Quote:
Subject:Thanks to linuxquestions.org
i copied the mail subject to a file. and now the issue is to creating a directory.

now i want to create a directory without empty spaces, insted of space replace _ in that place.

i want out put like this.

Quote:
Thanks_to_linuxquestions.org
please guide me to solve this issue.

With Regards
Anish Kumar.V
 
Old 03-11-2011, 12:58 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
One possible solution:
Code:
_name=$( echo ${_subject} | tr ' ' '_' )
 
Old 03-11-2011, 01:08 PM   #3
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi anomie,

Quote:
_name=$( echo ${_subject} | tr ' ' '_' )
quite complicated to understand this can you explain this command.!! that means really very helpful to me


With Regards
Anish Kumar.V
 
Old 03-11-2011, 01:15 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
In that command we have bash variable assignment, variable substitution, piping, and command substitution happening. You can read about all of those here: http://www.tldp.org/LDP/abs/html/

To learn what tr is doing, please read the tr(1) manpages, a la:
Code:
$ man tr
(If that's too cryptic, then search the 'net for more tr examples.)
 
1 members found this post helpful.
Old 03-11-2011, 01:42 PM   #5
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi anomie,

Thanks it works fine i understand with the help of some examples. thanks a lot dude :-)

Quote:
echo "Thanks to linux questions.org"|tr ' ' '_'
Thanks_to_linux_questions.org
With Regards
Anish Kumar.V
 
Old 03-12-2011, 09:17 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,491

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
If its bash and using a variable already you could also use:
Code:
subject='Subject:Thanks to linuxquestions.org'
echo ${suject// /_}
 
  


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
Concatenate two variables with underscore - question laki47 Linux - Newbie 3 06-04-2010 05:02 AM
sed, replacing underscore with whitespace fjkum Programming 3 10-31-2007 12:09 AM
C: fprintf with underscore jhwilliams Programming 8 08-25-2007 12:08 AM
deleting an underscore Post Modern Programming 2 11-27-2005 05:35 AM
HTML: How do I insert empty spaces? Cyberian Programming 3 02-10-2005 09:06 AM


All times are GMT -5. The time now is 11:59 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration