Formatting result file using Shell script
Hi All,
I have written a Shell script that produces the output like this The Server Name XXXXXX002 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 Up 512 User The Server Name XXXXXX003 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 down 512 User I want to differentiate the output here. In the second server one link status is Down, so I want All the servers whose link status is down should be in one file I mean the whole " The Server Name XXXXXX003 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 down 512 User" In a different file and Success results in a different file. Can we do that with Shell Scripting ? Regards, Athreya |
Yes, we can do this through shell scripting.
First, I would recommend you putting a keyword, say "VIKAS" in my example between output for each servers as :- Code:
VIKAS Then, use this command to put output of each server in different files Code:
awk '/vikas/{n++}{print > f n}' f=/vikas/op /vikas/output; Now, you can grep "down" in each file and join them as Code:
for i in `ls -lrt /vikas/ | awk '{print $9}' | grep op`; and /vikas/up where ink status is UP. Now, your task is to join all files whose filenames are in /vikas/down and /vikas/up. Just give it a try yourself and then ask if any problem occurs. Regards, VIKAS |
Hi Vikas,
Thanks for the reply. But this did not work for me. This is what I did. more filename | awk '/The Server Name/{n++} {print > f n}' f=/home/op /home/output these files are not getting created. I am all confused. Please help me on the same. Regards, Athreya VC |
Hi Vikas,
Sorry, It worked now. I was able to get it properly. Thanks a million for your Help. This case is "CLOSED" |
All times are GMT -5. The time now is 02:52 PM. |