Print in New line in loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print in New line in loop
# 1  
Old 12-10-2012
Print in New line in loop

Hi ,

i want to print the output in line by line

Code:
while read LINE
	 do
	     echo  $LINE | grep UCM | egrep '(Shutdown|Unavailable)' 
	echo  $LINE | grep SRBr | egrep '(Shutdown|Unavailable)' 
	echo  $LINE | grep SRP| egrep '(Shutdown|Unavailable)' 
	echo $LINE | grep OM | grep JMS| egrep '(Running|Online)' 
		  
	 done <output.log

but i m nt getting the output line by line

i tried echo"\n" in between grep stmnts ....not wrkin...pls help...
# 2  
Old 12-10-2012
Their are different version of echo which will work with
Code:
\n

and some will not.

Try this

Code:
echo "-e"

# 3  
Old 12-10-2012
It would be better to use printf than echo with non-standard options.

But I don't know why you'd need to unless there's a problem with your input file.

What exactly do you get (post the output)?
# 4  
Old 12-10-2012
Quote:
Originally Posted by navsan
Hi ,

i want to print the output in line by line

Code:
while read LINE
     do
         echo  $LINE | grep UCM | egrep '(Shutdown|Unavailable)' 
    echo  $LINE | grep SRBr | egrep '(Shutdown|Unavailable)' 
    echo  $LINE | grep SRP| egrep '(Shutdown|Unavailable)' 
    echo $LINE | grep OM | grep JMS| egrep '(Running|Online)' 
          
     done <output.log

but i m not getting the output line by line
Please write in English (write not, not nt, working, not wrkin, etc.).
The output should be in multiple lines, unless you're using some other code to display it. Please post the entire code.

By the way, something like this will be more efficient:

Code:
awk '/Shutdown|Unavailable/ {
    if (/UCM|SR(Br|P)/) print
  }
/OM/ && /JMS/ && /Running|Online/
  ' output.log

# 5  
Old 12-10-2012
navsan, if you are working on the same HTML report, I suggest you to put a HTML line break tag to display in newline. Putting a \n will not work for HTML
Code:
while read LINE
do
 echo $LINE | grep UCM | egrep '(Shutdown|Unavailable)'; echo "<br>"
 echo $LINE | grep SRBr | egrep '(Shutdown|Unavailable)'; echo "<br>" 
 echo $LINE | grep SRP| egrep '(Shutdown|Unavailable)'; echo "<br>" 
 echo $LINE | grep OM | grep JMS| egrep '(Running|Online)'; echo "<br>" 
done < output.log

I hope this helps.
# 6  
Old 12-10-2012
Code:
OM1 JMS JMSRdsfsdfds Rcvr RIA Background Running Manual 3 3 2012-12-10 11:22:58 OM2 JMS JMS RIA  Background Running Manual 3 3 2012-12-10 11:22:47 OM3  JMSRdsfsdfds Rcvr RIA Background Running Manual 3 3 2012-12-10 11:23:05 OM4  JMSRdsfsdfds Rcvr RIA Background Running Manual 3 3 2012-12-10 11:22:51

i m gettin like this.... i need like this

Code:
OM1 JMS JMSRdsfsdfds Rcvr RIA Background Running Manual 3 3 2012-12-10 11:22:58 
OM2 JMS JMS RIA  Background Running Manual 3 3 2012-12-10 11:22:47 
OM3  JMSRdsfsdfds Rcvr RIA Background Running Manual 3 3 2012-12-10 11:23:05 
OM4  JMSRdsfsdfds Rcvr RIA Background Running Manual 3 3 2012-12-10 11:22:51

---------- Post updated at 08:42 PM ---------- Previous update was at 08:36 PM ----------

hi bipinajith,

but its taking long spaces b/w evry line

---------- Post updated at 08:46 PM ---------- Previous update was at 08:42 PM ----------

hi bipinajith,

but its taking long spaces b/w evry line

Last edited by Scott; 12-10-2012 at 11:07 AM.. Reason: Code tags
# 7  
Old 12-10-2012
What does that mean?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo print on same line while loop using variable

Currently using below script but echo it print the output in two line. Input file all-vm-final-2.txt CEALA08893 SDDC_SCUN DS_SIO_Workload_SAPUI_UAT_01 4 CEALA09546 SDDC_SCUN DS-SIO-PD5_Workload_UAT_SP1_Flash_07 4 CEALA09702 SDDC_SCUN DS-VSAN-RMP-WORKLOAD01 4 DEALA08762 SDDC_LDC... (3 Replies)
Discussion started by: ranjancom2000
3 Replies

2. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies

3. UNIX for Beginners Questions & Answers

Loop through directory and print on line

In the bash below I am trying to loop through all the R1.gz in a directory (always 1), store them in ARRAY, and cut them before the second _. That is being done but I can't seem to print then one a single line seperated by a space. Is the below the best way or is there a better solution? Thank you... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Print loop output on same line dynamically

Hi, I am trying to print copy percentage completion dynamically by using the script below, #!/bin/bash dest_size=0 orig_size=`du -sk $sourcefile | awk '{print $1}'` while ; do dest_size=`du -sk $destfile | awk '{print $1}'` coyp_percentage=`echo "scale=2; $dest_size*100/$orig_size"... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

5. Shell Programming and Scripting

Find line then evaluate text on next line, print when condition is met

Hello, I am looking for a specific situation in a text file. The conditions are, > <CompoundName> InChI=1S/C5H12NO2/c1-5(2)4-8-6(3)7/h5H,4H2,1-3H3/q+1 I am looking for cases where the line "> <CompoundName>" is followed by a line that contains the string "InChI=" without regard to... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

6. Shell Programming and Scripting

Print awk output in same line ,For loop

My code is something like below. #/bin/bash for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'` do echo $i ORACLE_SID=`echo $line | awk '{print $2}'` USERNAME=`echo $line | awk '{print $1}'` done ============= But... (3 Replies)
Discussion started by: tapia
3 Replies

7. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

8. UNIX for Dummies Questions & Answers

loop? print max column in each line for 800 files and merge

Hello, I have 800 or so files with 3 columns each and >10000 lines each. For each file and each line I would like to print the maximum column number for each line. Then I would like to 'paste' each of these files together (column-wise) so that the file with expression in label '_1' is the... (6 Replies)
Discussion started by: peanuts48
6 Replies

9. Shell Programming and Scripting

Compare multiple fields in file1 to file2 and print line and next line

Hello, I have two files that I need to compare and print out the line from file2 that has the first 6 fields matching the first 6 fields in file1. Complicating this are the following restrictions 1. file1 is only a few thousand lines at most and file2 is greater than 2 million 2. I need to... (7 Replies)
Discussion started by: gillesc_mac
7 Replies
Login or Register to Ask a Question