![]() |
|
|
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 |
| total output from a file created in a while loop | Pablo_beezo | Shell Programming and Scripting | 7 | 01-29-2009 11:26 AM |
| While loop using command output... | elbombillo | Shell Programming and Scripting | 6 | 12-02-2008 04:47 PM |
| Loop column output | handband2 | UNIX Desktop for Dummies Questions & Answers | 1 | 11-03-2008 10:46 PM |
| Sed subsitution on loop output in shell script | Moxy | Shell Programming and Scripting | 2 | 09-28-2008 05:49 AM |
| Producing visually pleasant documents from plain text with reStructuredText and rst2a | iBot | UNIX and Linux RSS News | 0 | 04-29-2008 05:40 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sed in while loop producing arithmetic output
Hi all
Just wondering if someone can help me with this. I'm trying to write a script that processes the output of another file and prints only the lines I want from it. This is only the second script I have written so please bare with me here. I have referred to the literature and some of the previous posts and I'm sure I have the logic and syntax correct. It computes, but it takes ages and gives me the wrong output. heres the code: #Set the line number variables filelinenumber=1 datalinenumber=8 lines=`sed -n '$=' test1.out` while [ $datalinenumber -le $lines ] do # print the selected lines into the new file mpck2.out sed -n "${filelinenumber}p" test1.out` > mpck2.out sed -n "${datalinenumber}p" test1.out > mpck2.out # increment the line number variables filelinenumber=`expr $filelinenumber + 11` datalinenumber=`expr $datalinenumber + 11` done Instead of a file full of the program lines I want I'm just getting this $ cat mpck2.out average 156956 |
|
||||
|
Excellent! It Works. I Appreciate your help with that.
Its very good to see the code work. I will take a look at implementing the awk solution also if it requires less computation. I did notice that others have been referred to it in quite a few of the other posts. Cheers |
|
||||
|
I got the awk code to work too. It's impressively faster than calling sed. This code didn't quite work on my machine: Code:
awk ' BEGIN { fln = 1; dln = 8 }
NR == fln || NR == dln { print }
{ fln += 11; dln += 11 }
' test1.out > mpck2.out
However this did and it definitely pointed me in the right direction: Code:
awk ' BEGIN { fln = 1; dln = 8 }
NR == fln {print; fln += 11}
NR == dln {print; dln += 11}
' test1.out > mpckawk2.out
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|