LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 12: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 01:16 AM.
 
Old 03-31-2011, 01: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: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
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, 10: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 03-31-2011, 11:20 PM   #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 03-31-2011, 11:30 PM   #5
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
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 03-31-2011, 11:37 PM   #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, 12:44 AM   #7
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
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 12:46 AM.
 
1 members found this post helpful.
Old 04-01-2011, 02: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, 02: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 02:48 AM.
 
Old 04-01-2011, 11:25 AM   #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, 08: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, 08: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-06-2011, 11:24 PM   #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



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 06:19 PM
blank spacing in Vi LinuxNewbie999 Programming 1 11-10-2006 11:10 AM
Problem with frames in GTK+ - no spacing between frame and text entry Nylex Programming 8 03-01-2006 01:01 PM
Font Spacing darkjedi8359 Mandriva 1 01-12-2005 12:37 AM
font spacing zeb_666 Linux - General 0 05-01-2004 10:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:50 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
Open Source Consulting | Domain Registration