move a variable value from csh to awk ...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers move a variable value from csh to awk ...
# 1  
Old 08-02-2009
Question move a variable value from csh to awk ...

Guys,

following is my issue:
------------------------
Code:
#!/bin/csh
#     specify a counter
@ k = 1
#     loop
while ($k < 3)
#     read all text file with a specific number less than 3 in the last column of a record
foreach file ( *.txt)
#     capture the line by passing the column number using $k and print the record
awk -v  k="$k" '{j = NF; if ($j == k) print $0}'   $file
end
#     increment the counter
@ k = `expr $k + 1`
end

---------------------
I have accomplished this using the following:
Code:
#!/bin/csh
awk '{j = NF; if ($j == 1) print $0}' *.txt 
awk '{j = NF; if ($j == 2) print $0}' *.txt 
awk '{j = NF; if ($j == 3) print $0}' *.txt

Appreciate the help.
Regards
Z

Last edited by DukeNuke2; 08-02-2009 at 07:11 PM..
# 2  
Old 08-02-2009
The code:
Code:
if ($j == k)

needs to be:
Code:
if ($j == '$k')

and get rid of the:
Code:
k="$k"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to set variable permanent in csh?

We are using csh on our AIX platform, if we have to export/set a specific environment variable we use setenv command but its only valid till session. How do we set that variable permanent in our csh AIX? Do we put it in userprofile file or something else? (1 Reply)
Discussion started by: aixusrsys
1 Replies

2. Shell Programming and Scripting

Csh variable calling problem

First post on here. So I use csh shells for my research (physics... not a CS person). I am trying to rerun the same scripts, but there are ~10 files that have similar variables that I have to change for each different configuration, so I would like one central file for the variables I change that... (3 Replies)
Discussion started by: sabrepride
3 Replies

3. Shell Programming and Scripting

[CSH]legal to declare a variable like this

I am trying to declare a variable like this #!/bin/csh -f set c_arg = $a $b $c However, since i need it to declare before declaring $a ,$b or $c. As of now i am getting an error which says $a not defined. Is it possible to define a variable c_arg w/o interpreting the values $a $b $c (2 Replies)
Discussion started by: animesharma
2 Replies

4. Shell Programming and Scripting

arithmetic from csh variable passed to awk

I have the following code in a csh script I want to pass the value of the variable sigmasq to the awk script so that I can divide $0 by the value of sigmasq grep "Rms Value" $f.log \ | awk '{ sub(/*:*\.*/,x); \ print... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

Reading a variable in csh

I have a simple script that sets a value and reads the value in csh: set -x set a = 10 echo $a The output of the script does not show the value of a + set a = 10 + echo any help would be great. (4 Replies)
Discussion started by: pt14
4 Replies

6. Shell Programming and Scripting

help with multiline variable in csh

My shell is csh and it is required. I have a file like sample.txt ------------------------ a b c d e f g h i ------------------------ I want set the file to a variable and print it out in the same format. I have tried something like this, but not succed. % cat ~/tmp/sample.txt a b c d... (8 Replies)
Discussion started by: anykao
8 Replies

7. UNIX for Dummies Questions & Answers

address variable content with csh

By using a csh, I want to address a variable content whose name is/matches the content of a given other variable. i.e. set name=´sam´ set ${name}_age=´27´ So, by typing: echo ${name}_age I correctly obtain: sam_age By typing: echo $sam_age or echo ${sam_age} I correctly obtain: 27 ... (1 Reply)
Discussion started by: sobolev
1 Replies

8. Shell Programming and Scripting

declare number variable in csh

Hi frind, i="1" while do echo "i is $i" data_file=$HYP_ROOT/import/efcextr$i.txt echo "$data_file" i=`expr $i + 1` done This is woring finly in ksh but not in ksh. in ksh it showing error i=1: Command not found i: Undefined variable Kindly help me ...why it is showing the error... (1 Reply)
Discussion started by: deep_kol
1 Replies

9. Shell Programming and Scripting

Pass csh variable to Perl

Hi All, I am trying to put the csh variable into a perl. In the below case, i am trying to put the csh variable "var" into my perl code. I tried to use '"$var"' but i don;t think it works. Can anybody help me pls? #!/bin/csh set var = `echo "xxx"` perl myperlcode.pl file ... (9 Replies)
Discussion started by: Raynon
9 Replies

10. Shell Programming and Scripting

csh fails when setting variable

I have a csh that is called from autosys. It fails when it hits this code env | grep Rep if ( $status == 0 ) then echo "" else setenv REP "" endif However if I run it from the command line, as opposed to from autosys (job schduler) it runs fine. I thought it might be some kind of... (2 Replies)
Discussion started by: gillbates
2 Replies
Login or Register to Ask a Question