AWK in CSH script problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK in CSH script problems
# 1  
Old 09-22-2008
AWK in CSH script problems

Hello Guys,

I was trying to obtain the information from the /etc/passwd file, here was my script:
Code:
38 echo -n "What's your login name? "
 39 set logname=$<
 40 echo "Your login name is $logname, your user's ID is `grep $logname /etc/passwd|awk -F: '{print $3}'`"
 41 echo " Your home dir is `grep $logname /etc/passwd |awk -F: '{print $6}'`"

But I can't get the right answer. The result is as follows:
Code:
echo -n What's your login name?
What's your login name? zhihua
set logname=zhihua
echo Your login name is zhihua, your user's ID is `grep zhihua /etc/passwd|awk -F: '{print }'`
grep zhihua /etc/passwd
awk -F: {print }
Your login name is zhihua, your user's ID is zhihua:x:1000:1000:Zhihua,,,:/home/zhihua:/bin/bash
echo  Your home dir is `grep zhihua /etc/passwd |awk -F: '{print }'`
grep zhihua /etc/passwd
awk -F: {print }
 Your home dir is zhihua:x:1000:1000:Zhihua,,,:/home/zhihua:/bin/bash

It seems that in the awk segment, the shell replaces inner awk's parameters $N with the shell script's variables.

How can i avoid this problem? Thanks in advance!!
# 2  
Old 09-22-2008
As I tried many times, and now I have a fix: Do NOT use the double quotes around the awk command in echo
Code:
echo "Your login name is $logname, your user's ID is " `grep $logname /etc/passwd|awk -F: '{print $3}'`
echo "Your home dir is " `grep $logname passwd |awk -F: '{print $6}'`

If I add the double quotes around the awk, the csh interprets the $3 or $6 as the shell variables. And I still don't get it. Anyone knows please shed some light on this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting awk script from bash to csh

I have the following script set up and working properly in bash. It basically copies a set of lines which match "AS1100002" from one file and replaces the same lines in another file. awk -vN=AS1100002* 'NR==FNR { if($1 ~ N)K=$0; next } { if($1 in K) $0=K; print }' $datadir/file1... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

2. Shell Programming and Scripting

Problems editing file with awk in bash script

Hello dear users, here I have a script to manipulate .csv files that are like this originally: And I need to make a script to delete certain fields. Each field is separated with a comma. So, here is my script (at least a part of it): Field $1 is composed of a name, and then a... (5 Replies)
Discussion started by: sr00t
5 Replies

3. Shell Programming and Scripting

Calling awk fom csh

I have to call two awk scripts where the second one used the output from the first one. Am wondering if it may happen that the second awk might start before the first awk finished creating the file... if ($nAnomaly == 1) then awk -v anomaly=$Anom -v zloc="$zmin/$zmax" -v dz=$dz \ ... (1 Reply)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

Calling awk from csh

I am trying to call awk from a csh script using awk '{print $1, -$2, $3}' $fvmod.vel > $fvmod.xzv and getting awk: Command not found. Running awk '{print $1, -$2, $3}' $fvmod.vel > $fvmod.xzv on the command line with the actual filenames works (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

[AWK] Logparse script problems

Hey, I've gone through the code a number of times but I can't get the result that I want. If I run it on some big old maillogs then it basically doesn't give the right output. The script: #!/bin/awk -f BEGIN { delivery_count = 0; deferred_mail_count = 0; deliveries_failed =... (5 Replies)
Discussion started by: abciscool
5 Replies

6. UNIX for Dummies Questions & Answers

move a variable value from csh to awk ...

Guys, following is my issue: ------------------------ #!/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... (1 Reply)
Discussion started by: znbhatti
1 Replies

7. Shell Programming and Scripting

Array problems in CSH

Hi all, I want to use some commands and I wrap them into an array, like follows: set ALIAS_AR = ( "ls -ltr|wc -l" \ "ps -ef|grep -v grep |grep tty|wc -l" \ "who|wc -l" ) Then I use a while loop to call every step: set no = 1... (3 Replies)
Discussion started by: tpltp
3 Replies

8. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

9. Shell Programming and Scripting

How to plot graph using AWK or CSH?

Hi , i need to plot a x-y axis graph using AWK or CSH. Pls help. The data is as follows: 1 3 2 1 3 4 4 2 5 4 where 1st column refers to x-coordinate and 2nd column refers to y-coordinate. Note that x-coordinate may not be in sequence and the no of set of coordinates is unknown... (3 Replies)
Discussion started by: Raynon
3 Replies

10. Shell Programming and Scripting

command substitution problems with csh using grep

I am trying to set a command into a variable in a csh script using command substituion with ``. I am having a problem with ps command combined with grep. The command is as follows (shows processes running with the word gpts in them). /usr/ucb/ps axwww | grep gpts this works fine at the... (2 Replies)
Discussion started by: voodoo31
2 Replies
Login or Register to Ask a Question