Output formatting problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output formatting problem
# 1  
Old 05-21-2014
Output formatting problem

Hello;

I have a simple loop filtering a log:
Code:
for LU in $(< LU-list-Final)
do 
OUT=$(grep -B1 $LU cibc-src-ip.cap |egrep 'IP 16|IP 19|IP 15' |awk -F">" '{print $1}')
if [ "$OUT" != "" ]; then
echo " LU $LU was accessed by ===============> $OUT "
echo ""
fi
done

The current output snippet looks like this:
Code:
 LU CDC17175 was accessed by ===============> 2014-05-20 10:03:47.637360 IP 167.26.211.16.nimrod-agent

 LU CDC18089 was accessed by ===============> 2014-05-20 09:54:27.837523 IP 167.26.68.215.4488
2014-05-20 09:55:35.052801 IP 167.26.68.215.ipsec-nat-t
2014-05-20 10:05:24.791162 IP 167.26.68.215.netuitive

 LU cdc18111 was accessed by ===============> 2014-05-20 09:56:16.427882 IP 167.26.82.53.4755

I would like it so that when there are multiple lines for a LU string, they all line up like:

Code:
 LU CDC17175 was accessed by ===============> 2014-05-20 10:03:47.637360 IP 167.26.211.16.nimrod-agent

 LU CDC18089 was accessed by ===============> 2014-05-20 09:54:27.837523 IP 167.26.68.215.4488
                                                                                          2014-05-20 09:55:35.052801 IP 167.26.68.215.ipsec-nat-t
                                                                                          2014-05-20 10:05:24.791162 IP 167.26.68.215.netuitive

 LU cdc18111 was accessed by ===============> 2014-05-20 09:56:16.427882 IP 167.26.82.53.4755


Thnx for any suggestion

---------- Post updated at 10:43 AM ---------- Previous update was at 10:42 AM ----------

sorry I meant to line up by 2014-05-20
# 2  
Old 05-21-2014
try something along these lines and adjust as needed:
Code:
OUT=$(grep -B1 $LU cibc-src-ip.cap |egrep 'IP 16|IP 19|IP 15' |awk -F">" '{print (FNR==1)?$1:"\t\t" $1}')

# 3  
Old 05-21-2014
Quote:
Originally Posted by vgersh99
try something along these lines and adjust as needed:
Code:
OUT=$(grep -B1 $LU cibc-src-ip.cap |egrep 'IP 16|IP 19|IP 15' |awk -F">" '{print (FNR==1)?$1:"\t\t" $1}')

Thank you very much -- That worked
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies

2. Shell Programming and Scripting

Formatting the output

Hi, I have a file which contents entries in this form. Only in /data4/temp abc.000001 Only in /data4/temp abc.000003 Only in /data4/temp abc.000012 Only in /data4/temp abc.000120 Only in /data4/temp abc.000133 Only in /data4/temp abc.001444 i want to read line by line and format... (2 Replies)
Discussion started by: arijitsaha
2 Replies

3. Shell Programming and Scripting

Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys.. Need your help to format the output of my shell script. I am using spool command to take out put in csv file. below is my code. (for example) col USERNAME for a15 col EMAIL for a30 col FULL_NAME for a20 col LAST_LOGIN for a40 col DATE_CREATED for a40 SPOOL 120.csv... (3 Replies)
Discussion started by: Agupte
3 Replies

4. Shell Programming and Scripting

Formatting output

Hi, I have a file like this -------------------------- 1 aaa xxx 55 -------------------------- 1 aaa www 32 -------------------------- 2 bbb yyy 11 -------------------------- 2 bbb zzz 34 ------------------------- 2 bbb ttt ... (3 Replies)
Discussion started by: tdev457
3 Replies

5. Shell Programming and Scripting

Output formatting .

below is a CPU utilization Log for ABC server. However for every 15 minutes it generates 3 CPU values(with interval of 2 sec). Host CPU CPUtotal CPU% time ABC 101.1 2 50.55 14 : 15 ABC 100.5 2 50.25 14 : 15 ABC 100.2 2 50.1 14 : 15 ABC 100.9 2 50.45 14 : 30 ABC 100.5 2 50.25 14 : 30 ABC... (5 Replies)
Discussion started by: pinga123
5 Replies

6. Shell Programming and Scripting

Formatting of output

Hi Experts, I have to create a report for certain audit and my output looks as follows I m trying to format my output to look like Any inputs would be highly appreciated Thanks Syed (5 Replies)
Discussion started by: maverick_here
5 Replies

7. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

8. Shell Programming and Scripting

formatting output

my script is as follows cnt=`ps -ef |grep pmon|grep -v grep|awk 'END {{print NR}}'` cnt2=`ps -ef |grep tns|grep -v grep|awk 'END {{print NR}}'` if then if then rman target/ catalog recdb/recdb@recdb cmdfile report_need_backup.sql > report_need_backup.txt ... (1 Reply)
Discussion started by: swkambli
1 Replies

9. Shell Programming and Scripting

output formatting problem

I would like to keep the complete lines in the output, but my script adds carriage returns for each space (e.g. keep BRITISH AIRWAYS on one line in the output): File1= BAW BRITISH AIRWAYS RYR RYAN AIR for i in $(cat File1) do echo $i done Output: BAW BRITISH AIRWAYS RYR... (4 Replies)
Discussion started by: barny
4 Replies

10. Linux

Output formatting problem..Plz hlp

Hi guys, It will be a great help if somebody can help me in following problem. I have tried hard but because of lack of UNIX/LINUX knowledge I am not able to do it. I have written a script that returns 3 things of all the employees in my organisation. i.e. Name, Login time & log out time of... (2 Replies)
Discussion started by: anushree.a
2 Replies
Login or Register to Ask a Question