a simple loop in csh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers a simple loop in csh
# 1  
Old 05-21-2008
a simple loop in csh

Hello,

I have a file with over 48000 lines and I need to select certain parts of the file. I know which awk commands work for what I need, I just need some help putting together a loop that will repeat the command. These are the commands that work:

awk 'NR < 6' plot.out > plot.test (I get the first 5 lines of plot.out)

awk 'NR==15,NR==17' plot.out >> plot.test (now I need these lines)
awk 'NR==30,NR==32' plot.out >> plot.test (etc.)
awk 'NR==45,NR==47' plot.out >> plot.test
awk 'NR==60,NR==62' plot.out >> plot.test
awk 'NR==75,NR==77' plot.out >> plot.test
awk 'NR==90,NR==92' plot.out >> plot.test
awk 'NR==105,NR==107' plot.out >> plot.test
awk 'NR==120,NR==122' plot.out >> plot.test
awk 'NR==135,NR==137' plot.out >> plot.test


Please help. All the loops I make don't work Smilie I know this is simple for somebody out there.....
# 2  
Old 05-22-2008
Quote:
Originally Posted by dsstamps
Hello,

I have a file with over 48000 lines and I need to select certain parts of the file. I know which awk commands work for what I need, I just need some help putting together a loop that will repeat the command. These are the commands that work:

awk 'NR < 6' plot.out > plot.test (I get the first 5 lines of plot.out)

awk 'NR==15,NR==17' plot.out >> plot.test (now I need these lines)
awk 'NR==30,NR==32' plot.out >> plot.test (etc.)
awk 'NR==45,NR==47' plot.out >> plot.test
awk 'NR==60,NR==62' plot.out >> plot.test
awk 'NR==75,NR==77' plot.out >> plot.test
awk 'NR==90,NR==92' plot.out >> plot.test
awk 'NR==105,NR==107' plot.out >> plot.test
awk 'NR==120,NR==122' plot.out >> plot.test
awk 'NR==135,NR==137' plot.out >> plot.test


Please help. All the loops I make don't work Smilie I know this is simple for somebody out there.....


I see that NR is incremented by 15

cat plot.out|awk -v x=15 'NR==x,NR==x+2 {x=x+15};END{print $0}'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Foreach loop through subdirectories in csh

Hi You might find it very trivial but actually don't know how to loop through all sub-directories and their child directories into a csh. bash was easier I believe but here I am, stuck with csh. So elaborately here's my problem: Let's say I have my parent directory named C-H/ under which I have... (15 Replies)
Discussion started by: saleheen
15 Replies

2. Shell Programming and Scripting

CSH While Loop

Hi all, How can I make this work with CSH: set K=3 set I=1 while ($I != $K) echo "K="$I @ I = $K + 1 end Any help you can provide or links that can help is greatly appreciated. With above I get an error "while: Expression Syntax" (3 Replies)
Discussion started by: manglalayag
3 Replies

3. UNIX for Dummies Questions & Answers

foreach loop in csh

Hi everyone I'm new to unix and encountered a small problem i couldnt find out a reason why it doesn't work..please help.. in my csh script when i tried to use the foreach loop like this: foreach x ( ls ) echo $x end when i tried to run it, it printed out 'ls' to the std out instead of... (3 Replies)
Discussion started by: ymc1g11
3 Replies

4. UNIX for Dummies Questions & Answers

Problem with simple csh scripting

I found my answer... (2 Replies)
Discussion started by: sjung9442
2 Replies

5. Shell Programming and Scripting

Creating a loop in csh

I have the following code and want to use a loop to output the results to the fparams file. if ($optparams == 1) then # Set the tdarwin parameters set txt01 = "Call to raytrac.csh" set txt02 = "" set txt03 = "./Scripts/raytrac.csh $*" set txt04 = "" set txt05 =... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

How to loop use while loop in csh script?

Hi all, i got 2 text file. file.txt value.txt i want use C shell script to write out while both of the file got different limit....how i going to write it in 1 while loop? (4 Replies)
Discussion started by: proghack
4 Replies

7. Shell Programming and Scripting

simple csh script

Hi This little script is giving me error: Syntax error at line xxx : `(' is not expected. Wgat did I miss? RC=0 switch ( $RC ) case 0: echo Done breaksw case -1: echo not done breaksw default: echo "Hello" endsw (2 Replies)
Discussion started by: nimo
2 Replies

8. Shell Programming and Scripting

Simple CSH script

Hi everyone, I have never wrote script in csh before, but I need to add only few lines to an existing one. I tried to use the bash standard syntax, and it did not work. So, I attempted to use csh syntax, and it is not working. Can someone help please: switch ( $Return_Code ) case 0:... (3 Replies)
Discussion started by: nimo
3 Replies

9. Shell Programming and Scripting

simple CSH Script behaves differently on Solaris and RedHat Linux

I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator: #!/bin/csh set shz=2 set zshift=5 set shzp=`bc -l <<END \ scale = 3 \ -1. * $shz + $zshift \ END` echo $shzp The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8. ... (2 Replies)
Discussion started by: two reelers
2 Replies

10. Shell Programming and Scripting

csh exit while loop on keystroke

#!/bin/csh I'm using a `while(1)` loop to dispaly real-time information about various files on my system, and I use ^C to exit it when needed. I was hoping there was a way to exit the script on a normal keystroke such as "q". Can someone point me in the right direction? I'm willing to use a... (7 Replies)
Discussion started by: seg
7 Replies
Login or Register to Ask a Question