![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to print only lines in between two strings using awk | jisha | Shell Programming and Scripting | 4 | 01-11-2008 04:13 AM |
| print selected lines | tonet | Shell Programming and Scripting | 6 | 10-08-2007 05:50 AM |
| How to print number of lines with awk ? | maheshsri | Shell Programming and Scripting | 1 | 11-18-2005 02:19 AM |
| print adjacent lines | apalex | UNIX for Dummies Questions & Answers | 1 | 04-29-2002 11:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Help Needed - print mutliple lines
I have the following input
-- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 2.999 select emp_no, dept_no from emp where empname like 'Rob%' and empno=10 ; -- appl = host = user = / pid = 76 elapsed = 0.000 seconds server_elapsed = 0.999 select emp_no, dept_no from dept where deptname like 'IT%' ; The above input need to print the following output. 2.999 |select emp_no, dept_no from emp where empname like 'Rob%' and empno=10; 0.999 |select emp_no, dept_no from dept where deptname like 'IT%' ; I have files with thousands of statements, I need to format them as above. I appreciate your kind help and reply. |
|
||||
|
Quick and dirty code to re-format your queries - assumes that each one starts with a comment preceded by "--"
Code:
while read a do if [[ $a = --* ]]; then print lf=$(echo $a|wc -w); print -n "$(echo $a|cut -d' ' -f $lf) |" else print -n " "$a fi done < YourOriginalFile > YourReformattedFile |
|
||||
|
Wow ...
Thanks for your quick and dirty code to solve my problem. As I am a new to this kind of work, I could not able to understand the solution but it is great. I have one more request to the output. If I need only specific rows like I do not want 0.000 rows to the out put. then How can I proceed. I know one way, to do this by grep -v. But anyother way.
Thanks for your reply and help. |
|
||||
|
That awk line is terrific!
But using shell script with same assumptions as before, to suppress zeros: Code:
while read a
do
if [[ $a = --* ]]; then
lf=$(echo $a|wc -w)
secs=$(echo $a|cut -d' ' -f $lf)
msecs=$(( $secs * 1000))
if [ $msecs -gt 0 ]; then
print
print -n "$secs |"
fi
else
if [ $msecs -gt 0 ]; then
print -n " "$a
fi
fi
done < YourOriginalFile > YourReformattedFile
|
| Sponsored Links | ||
|
|