1748198 Members
2657 Online
108759 Solutions
New Discussion юеВ

file output formatting

 
SOLVED
Go to solution
PING_6
Esteemed Contributor

file output formatting

Hi Experts,

I want to prcess a file on output as shown below pls help me

the output of the file is like

1 nn.abc.com Reachable
2 node_name.xyz.com Reachable
3 test_node Not Reachable

instead i want the output as

1 nn.abc.com Reachable
2 node_name.xyz.com Reachable
3 test_node Not Reachable

I have a small script which will test for node reachability where the output is found to be jumbled because of the node names

pls guide me to get this required format

Thanks
Whatever exists is changeable and what is not changeable does not exist.
10 REPLIES 10
Suraj K Sankari
Honored Contributor

Re: file output formatting

Hi,

>>the output of the file is like

>>1 nn.abc.com Reachable
>>2 node_name.xyz.com Reachable
>>3 test_node Not Reachable

>>instead i want the output as
>>1 nn.abc.com Reachable
>>2 node_name.xyz.com Reachable
>>3 test_node Not Reachable

I didn't find any difference between your output file and what you want.

Suraj
Suraj K Sankari
Honored Contributor

Re: file output formatting

Hi again,

Where is your input file ?

Suraj
PING_6
Esteemed Contributor

Re: file output formatting

Hi Suraj,

I want equal spacing irespective ov the node name size.My Fields are S.No,Node Name & Status.

In this output id the nodename is short the status is printed near to that if the node name is long then the status is printed accordingly instead of this i want the output to be equally spaced like the contentes of any table.

Thanks
Whatever exists is changeable and what is not changeable does not exist.
Suraj K Sankari
Honored Contributor

Re: file output formatting

Hi,

see the below things

[root@rspc521 suraj]# cat data
1 nn.abc.com Reachable
2 node_name.xyz.com Reachable
3 test_node Not Reachable

[root@rspc521 suraj]# cat p
awk '{ printf "%-3s %-20s %s %s\n", $1,$2,$3,$4 }' data

[root@rspc521 suraj]# sh p
1 nn.abc.com Reachable
2 node_name.xyz.com Reachable
3 test_node Not Reachable

Suraj
Suraj K Sankari
Honored Contributor

Re: file output formatting

Hi,

Here you can't see the formated output
I hope you can see at your server in proper format.

Suraj
PING_6
Esteemed Contributor

Re: file output formatting

suraj pls find my requirement attached
Whatever exists is changeable and what is not changeable does not exist.
PING_6
Esteemed Contributor

Re: file output formatting



>>>[root@rspc521 suraj]# cat p
awk '{ printf "%-3s %-20s %s %s\n", $1,$2,$3,$4 }' data

pls clarify this

data is my input file, that fine

Let me know how eactly i should type the above command

Also if possible pls explain the awk params

Whatever exists is changeable and what is not changeable does not exist.
Suraj K Sankari
Honored Contributor

Re: file output formatting

Hi,

Saw your attached file you will get the same output if you do what i said .

just open a file suppose p
paste this below line

awk '{ printf "%-s %-20s %s %s\n", $1,$2,$3,$4 }' data

save the file
now at the command prompt type make sure your input file data in the same folder

# sh p
you will get the output as you said

see the link below to know about AWK

http://en.wikipedia.org/wiki/AWK

Suraj
Suraj K Sankari
Honored Contributor
Solution

Re: file output formatting

Hi Again,

Forget to attached my output file.

Find the attached file

Suraj