LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   spacing (https://www.linuxquestions.org/questions/linux-newbie-8/spacing-872054/)

athrin 03-31-2011 12:06 AM

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

EricTRA 03-31-2011 01:47 AM

Quote:

Originally Posted by athrin (Post 4309191)
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

rrije 03-31-2011 10:12 AM

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.

athrin 03-31-2011 11:20 PM

Quote:

Originally Posted by rrije (Post 4309711)
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..

kurumi 03-31-2011 11:30 PM

Quote:

Originally Posted by rrije (Post 4309711)
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

paulsm4 03-31-2011 11:37 PM

Quote:

Q: why the cat and the extra single quotes?
Because it's arguably clearer :)

kurumi 04-01-2011 12:44 AM

Quote:

Originally Posted by paulsm4 (Post 4310288)
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.

athrin 04-01-2011 02:29 AM

Quote:

Originally Posted by rrije (Post 4309711)
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

athrin 04-01-2011 02:35 AM

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

paulsm4 04-01-2011 11:25 AM

Hi, Athrin -

As an example, this command adds six spaces:
Code:

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

'Hope that helps

athrin 04-02-2011 08:16 PM

Quote:

Originally Posted by paulsm4 (Post 4310862)
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

rrije 04-04-2011 08:08 AM

Quote:

Originally Posted by kurumi (Post 4310281)
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).

athrin 04-06-2011 11:24 PM

Quote:

Originally Posted by rrije (Post 4313312)
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


All times are GMT -5. The time now is 07:30 AM.