Grep result loses formatting


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Grep result loses formatting
# 1  
Old 07-21-2010
Grep result loses formatting

I am searching for a string in a file and then redirecting the contents in another file... however the formatting is not preserved.. Can you please help me on this ...
# 2  
Old 07-21-2010
Hi.

There is no reason the formatting should be changed (when using grep).

Can you please show the command you are using, and a sample of the data?
# 3  
Old 07-21-2010
This is result of grep
Code:
PER QUEUED | NORMAL FINAL CREDIT CR/FIN INACTV LOCKED SKIP ERROR | MISSING
--- ------ | ------ ------ ------ ------ ------ ------ ------ ------ | -------
J28 2 | 2 0 0 0 0 0 0 0 | 0
T01 88 | 34 0 0 0 54 0 0 0 | 0
T10 4 | 1 0 0 0 3 0 0 0 | 0
T15 6 | 6 0 0 0 0 0 0 0 | 0
--- ------ | ------ ------ ------ ------ ------ ------ ------ ------ | -------
TOT 100 | 43 0 0 0 57 0 0 0 | 0
=== ====== | ====== ====== ====== ====== ====== ====== ====== ====== | =======

Original text
Code:
PER   QUEUED | NORMAL  FINAL CREDIT CR/FIN INACTV LOCKED   SKIP  ERROR | MISSING
---   ------ | ------ ------ ------ ------ ------ ------ ------ ------ | -------
J28        2 |      2      0      0      0      0      0      0      0 |      0
T01       88 |     34      0      0      0     54      0      0      0 |      0
T10        4 |      1      0      0      0      3      0      0      0 |      0
T15        6 |      6      0      0      0      0      0      0      0 |      0
---   ------ | ------ ------ ------ ------ ------ ------ ------ ------ | -------
TOT      100 |     43      0      0      0     57      0      0      0 |      0
===   ====== | ====== ====== ====== ====== ====== ====== ====== ====== | =======

This is command that i m using
grep -A 31 "PROCESS ID" $obj

---------- Post updated at 03:19 PM ---------- Previous update was at 03:03 PM ----------

I think i was doing it wrong its not grep its echo

Code:
grep -A 31 "PROCESS ID" $obj | while read obj2
do
echo $obj2 > filename
done

can you suggest how to work around this.

Last edited by Scott; 07-21-2010 at 06:58 AM.. Reason: Code tags
# 4  
Old 07-21-2010
Smilie

Try quoting the echo...
Code:
grep -A 31 "PROCESS ID" $obj | while read obj2
do
echo "$obj2" > filename
done

# 5  
Old 07-21-2010
Thanks mate it worked...
However i am facing one more problem

Code:
touch -t `date +%m%d0000` /tmp/$$
queued_total=0
processed_total=0
locked_total=0
error_total=0

find /apps/path/reports/ctrl/ -type f -newer /tmp/$$ | grep BIP_ | while read obj
do
echo "$obj">> /apps/path/report_$log_date.log
echo "_______________________________________________________________________________________________________________">> /apps/home/testfit01/report_$log_date.log
grep -E -A 31 "PROCESS ID" "$obj"  | while read obj2
do
if echo $obj2| grep -q "TASK ID:"; then
echo "$obj2">> /apps/path/report_$log_date.log
fi
if echo $obj2| grep -q "TOTAL ACCOUNTS QUEUED"; then
queued=`echo "$obj2" | cut -f2 -d ':'`
queued_total=`expr $queued_total + $queued`
echo "$obj2">> /apps/path/report_$log_date.log
fi
if echo $obj2| grep -q "TOTAL SUCCESSFULLY PROCESSED"; then
echo "$obj2">> /apps/path/report_$log_date.log
processed=`echo "$obj2" | cut -f2 -d ':'`
processed_total=`expr $processed_total + $processed`
fi
if echo $obj2| grep -q "TOTAL LOCKED/SKIPPED"; then
echo "$obj2">> /apps/home/testfit01/report_$log_date.log
locked=`echo "$obj2" | cut -f2 -d ':'`
locked_total=`expr $locked_total + $locked`
fi
if echo $obj2| grep -q "TOTAL IN ERROR"; then
echo "$obj2">> /apps/path/report_$log_date.log
error=`echo "$obj2" | cut -f2 -d ':'`
error_total=`expr $error_total + $error`
echo "_______________________________________________________________________________________________________________">> /apps/home/testfit01/report_$log_date.log
fi
done
echo " ">> /apps/path/report_$log_date.log
echo " ">> /apps/path/report_$log_date.log
done

echo "Total Queued      : $queued_total"
echo "Total Processed   : $processed_total"
echo "Total Locked      : $locked_total"
echo "Total Error       : $error_total"

I am getting 0 for all totals. Can you help.
# 6  
Old 07-23-2010
The data in post #3 does not appear to relate to the script.

Can we see the data file (or files??) containing:

Code:
"PROCESS ID"
"TASK ID:"
"TOTAL ACCOUNTS QUEUED"
"TOTAL SUCCESSFULLY PROCESSED"
"TOTAL LOCKED/SKIPPED"
"TOTAL IN ERROR"


Last edited by methyl; 07-23-2010 at 01:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep result from dd command

Hi, I am running following command in a bash script for testing IO and use grep to get throughput number, but it did not work, it displayed everything: dd if=/dev/zero of=/dev/null bs=1G count=1 oflag=dsync | grep bytes | awk '{print $7}' 1+0 records in 1+0 records out 536870912 bytes... (2 Replies)
Discussion started by: hce
2 Replies

2. Shell Programming and Scripting

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

3. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

4. Solaris

grep result in newline

Hi While trying to do a search on solaris, the grep results seems to be appearing on the same line instead of the new line. Wed Jan 18 14:45:48 weblogic@test:/abcd$ grep qainejb02 * qa_cluster_biz_view_tc_intl_servers_ports_2:qainejb02 7101 qa_cluster_servers_2:qainejb02... (2 Replies)
Discussion started by: ganga.dharan
2 Replies

5. Shell Programming and Scripting

pipe result from grep

Trying to create a command line script to look for all files matching a pattern, grep for a specific value in each file, and write out the filename long list. It's possible the filename won't containe the value. { echo “Running....” for fname in 811_Intermediate_File_* do grep -l... (3 Replies)
Discussion started by: gavineq
3 Replies

6. Shell Programming and Scripting

How to negate grep result?

Here is my script so far: set dirs = ` find . -name "message.jar" 2> /dev/null | cut -d "/" -f 2 ` | uniq foreach dir ( $dirs ) if (grep $dir/* someText==null) --> how do I write this in script? print $dir end end (4 Replies)
Discussion started by: mmdawg
4 Replies

7. Shell Programming and Scripting

diaplaying the grep result

Hi, My code is like this if swlist -a revision 2>/dev/null | grep ABC 2>/dev/null then echo "Found Above mentioned ABC Version, please remove it first..." fi This is displaying the result to the screen. i want to first suppress that and for that i wrote the below... (1 Reply)
Discussion started by: rag84dec
1 Replies

8. Shell Programming and Scripting

formatting the sql select result

Hi, I have about 12 columns and 15 rows to be retrived from sybase isql command through unix. But when i output the sql into a file and see it, the formatting is going for a toss. can someone please suggest how can i get the result correctly in the output file ? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies

9. UNIX for Dummies Questions & Answers

grep to handle a 0 result

Hi guys, I have the following grep command in a script to search through a file for a string and return its count, and it works fine for when the string exists: grep "string" file.txt | wc However, sometimes the result will be 0 and I want the script to take this as the result. Right now... (6 Replies)
Discussion started by: ocelot
6 Replies

10. UNIX for Dummies Questions & Answers

To have a numeric result from grep

I am new to unix. i need to know how to use grep to grep and expression from a file. and pass the result as a 0 for found and 1 for not found. I can only go up to grep 'Checking Subscription Status' ranos.log. Please help. Thank you. (2 Replies)
Discussion started by: Hak Dee
2 Replies
Login or Register to Ask a Question