LinuxQuestions.org
Help answer threads with 0 replies.
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-31-2011, 01:06 AM   #1
athrin
Member
 
Registered: Mar 2011
Posts: 135

Rep: Reputation: 1
spacing


hello i want to display
THIS
Hostname : dell
Ip address : 192.168.1.103
CPU Name : Intel(R) Xeon(TM) CPU 2.40GHz

TO

Hostname <space> : dell
Ip address <space> : 192.168.1.103
CPU Name <space> :Intel(R) Xeon(TM) CPU 2.40GHz

made the : to one line using bash
please help me

Last edited by athrin; 03-31-2011 at 02:16 AM.
 
Old 03-31-2011, 02:47 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by athrin View Post
made the : to one line using bash
Hello,

What do you mean by this? Have a look at the man page for sed:
Code:
man sed
or this great tutorial of sed online.

Kind regards,

Eric
 
Old 03-31-2011, 11:12 AM   #3
rrije
Member
 
Registered: Jul 2010
Distribution: openSUSE 11.4
Posts: 33

Rep: Reputation: Disabled
You probably want to line up the second column straight, right?

Try sed s/':'/':\t'/g
'\t' will insert tabulation (equal to several spaces).

So, for example, if you have a file "input" with the text you want to transform, you do something like this:
Code:
cat input | sed s/':'/':\t\t'/g > output
The resulting file "output" will have the processed text.
 
Old 04-01-2011, 12:20 AM   #4
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by rrije View Post
You probably want to line up the second column straight, right?

Try sed s/':'/':\t'/g
'\t' will insert tabulation (equal to several spaces).

So, for example, if you have a file "input" with the text you want to transform, you do something like this:
Code:
cat input | sed s/':'/':\t\t'/g > output
The resulting file "output" will have the processed text.
oh... thanks..
 
Old 04-01-2011, 12:30 AM   #5
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 45
Quote:
Originally Posted by rrije View Post
Code:
cat input | sed s/':'/':\t\t'/g > output
The resulting file "output" will have the processed text.
why the cat and the extra single quotes?
Code:
sed 's/:/:\t\t/' input
 
Old 04-01-2011, 12:37 AM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Q: why the cat and the extra single quotes?
Because it's arguably clearer
 
Old 04-01-2011, 01:44 AM   #7
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 45
Quote:
Originally Posted by paulsm4 View Post
Because it's arguably clearer
how is that clearer and simpler than passing the file as input and reducing extra shell processes?? Besides, the main purpose of cat is to concat files, not really to view.

Last edited by kurumi; 04-01-2011 at 01:46 AM.
 
1 members found this post helpful.
Old 04-01-2011, 03:29 AM   #8
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by rrije View Post
You probably want to line up the second column straight, right?

Try sed s/':'/':\t'/g
'\t' will insert tabulation (equal to several spaces).

So, for example, if you have a file "input" with the text you want to transform, you do something like this:
Code:
cat input | sed s/':'/':\t\t'/g > output
The resulting file "output" will have the processed text.
wait2.. how to use this again??
im using "\ \ " to space.. but if you have other command tell me
 
Old 04-01-2011, 03:35 AM   #9
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
example i use this command for spacing

OS=`cat /etc/*release`
echo "OS Used" \ \ \ \ \ \ \ \ \ \ \ \ \ " : $OS"

but the command doesnt look nice if i use this.
so how to change the \ \ to other command using your

cat input | sed s/':'/':\t\t'/g > output

Last edited by athrin; 04-01-2011 at 03:48 AM.
 
Old 04-01-2011, 12:25 PM   #10
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, Athrin -

As an example, this command adds six spaces:
Code:
OS=`cat /etc/*release`
echo "OS Used:      $OS"
'Hope that helps
 
Old 04-02-2011, 09:16 PM   #11
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by paulsm4 View Post
Hi, Athrin -

As an example, this command adds six spaces:
Code:
OS=`cat /etc/*release`
echo "OS Used:      $OS"
'Hope that helps
nope.. its not helping.. now i'm using
Code:
OS=`cat /etc/*release`
echo "OS Used"'      '" :$OS"
i think this is enough
 
Old 04-04-2011, 09:08 AM   #12
rrije
Member
 
Registered: Jul 2010
Distribution: openSUSE 11.4
Posts: 33

Rep: Reputation: Disabled
Quote:
Originally Posted by kurumi View Post
why the cat and the extra single quotes?
I'm not much of a scriptwriter (neither have a solid knowledge on how to use bash properly), so thanks for pointing that out. Guess I'm just not really sure about the outcome of this and that, and code redundancy gives an illusion of simplicity.

Anyway, athrin, I don't understand why you insist on using spaces instead of tabs, because tabs (as far as I know) have a nice property of lining things straight, so it doesn't matter if the text before the tabs is a bit shorter or longer.

echo -e "OS Used"\t\t":$OS"
looks simpler to me (-e option enables interpretation of backslash escape sequences).
 
1 members found this post helpful.
Old 04-07-2011, 12:24 AM   #13
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by rrije View Post
I'm not much of a scriptwriter (neither have a solid knowledge on how to use bash properly), so thanks for pointing that out. Guess I'm just not really sure about the outcome of this and that, and code redundancy gives an illusion of simplicity.

Anyway, athrin, I don't understand why you insist on using spaces instead of tabs, because tabs (as far as I know) have a nice property of lining things straight, so it doesn't matter if the text before the tabs is a bit shorter or longer.

echo -e "OS Used"\t\t":$OS"
looks simpler to me (-e option enables interpretation of backslash escape sequences).
oh 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] spacing henrtm05 Linux - Newbie 10 10-01-2010 07:19 PM
blank spacing in Vi LinuxNewbie999 Programming 1 11-10-2006 12:10 PM
Problem with frames in GTK+ - no spacing between frame and text entry Nylex Programming 8 03-01-2006 02:01 PM
Font Spacing darkjedi8359 Mandriva 1 01-12-2005 01:37 AM
font spacing zeb_666 Linux - General 0 05-01-2004 11:29 AM


All times are GMT -5. The time now is 02:40 PM.

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