Converting awk script from bash to csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting awk script from bash to csh
# 1  
Old 02-18-2014
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.

Code:
awk -vN=AS1100002*  'NR==FNR { if($1 ~ N)K[$1]=$0; next }
{ if($1 in K) $0=K[$1]; print }' $datadir/file1 $datadir/file2  > $datadir/file2.new

But in csh I get the following error when running:

Code:
Unmatched '.

Any ideas on how to fix this issue?

Thanks!
# 2  
Old 02-18-2014
That should not be the case nor should it happen, unless you copied/paste the code you submitted: When using GUI the selection of 2 lines is understood "AS" 2 lines and will put a en of line and the end of first line... You remove it and Im sure it works... e.g. in vi you use J to join both lines...
Code:
awk -vN=AS1100002*  'NR==FNR { if($1 ~ N)K[$1]=$0; next }\
 { if($1 in K) $0=K[$1]; print }'\
 $datadir/file1 $datadir/file2  > datadir/file2.new

# 3  
Old 02-18-2014
It works fine on the command line. I get the error when running the script.
# 4  
Old 02-18-2014
In csh the backslash should be outside the 'string'
Code:
echo \
'part 1'\
'part 2'

--
You certainly want -vN=AS1100002 i.e. without trying to match files in the current directory or allowing several 2 at the end.

Last edited by MadeInGermany; 02-18-2014 at 10:51 AM..
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 02-18-2014
Quote:
Originally Posted by MadeInGermany
In csh the backslash should be outside the 'string'
Code:
echo \
'part 1'\
'part 2'

When adding in a backslash

Code:
awk -vN=AS1100002* 'NR==FNR { if($1 ~ N)K[$1]=$0; next }'\
'{ if($1 in K) $0=K[$1]; print }' $datadir/file1 $datadir/file2 > $datadir/file2.new

I get

Code:
awk: No match.

# 6  
Old 02-18-2014
Just tested on AIX:
Code:
awk -vN=AS1100002*  'NR==FNR { if($1 ~ N)K[$1]=$0; next } { if($1 in K) $0=K[$1]; print }'\
 $datadir/file1 $datadir/file2  > $datadir/file2.new

works...

So what is in your csh script then? If you doubt about the awk line, just put that in a file and execute it with csh:
Code:
 csh -x file

# 7  
Old 02-18-2014
Just realised:
Code:
awk: No match.

Means thats its working... Only awk found no match...
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting macro to bash script

Gents, Please can you help me with this. When column 49 == 2 Before X 4714 14710 69445.00 19257.001 1218 12271 69596.00 19460.00 19478.001 X 4714 14710 69445.00 19257.001 1228 12292 69596.00 19480.00 19480.001 After X 4714 14710 69445.00 19257.001 1218... (1 Reply)
Discussion started by: jiam912
1 Replies

2. Shell Programming and Scripting

Changing script from csh to bash

Hello Guys I have a script working fine on csh, but I would like to change it to bash, how I should change this command to be able to work as bash script. :wall: if ( $fsw > "0" ) then foreach swath ( `awk 'BEGIN {for (i='$fsw';i<='$lsw';i++) printf ("%s\n", i) }'` ) ## work to be done... (2 Replies)
Discussion started by: jiam912
2 Replies

3. Shell Programming and Scripting

Please help me with converting the below bash script in C shell script

#!/bin/sh # $Header: hot_database_backup.sh,v 1.2 2002/08/06 23:51:42 $ # #bcpyrght #*************************************************************************** #* $VRTScprght: Copyright 1993 - 2007 Symantec Corporation, All Rights Reserved $ *... (2 Replies)
Discussion started by: apade
2 Replies

4. Shell Programming and Scripting

Converting date/time and generating offsets in bash script

Hi all, I need a script to do some date/time conversion. It should take as an input a particular time. It should then generates a series of offsets, in both hour:minute form and number of milliseconds elapsed. For 03:00, for example, it should give back 04:02:07 (3727000ms*) 05:04:14... (2 Replies)
Discussion started by: emdan
2 Replies

5. Shell Programming and Scripting

Need a script to convert csh to bash

Hi, Can anyone give me a script to convert csh to bash? or any key points which can help me to do so as i am new to it. (3 Replies)
Discussion started by: vineet.dhingra
3 Replies

6. Shell Programming and Scripting

How to run a bash script in csh shell?

Hi how to execute a bash script in csh shell? Thanks (3 Replies)
Discussion started by: rubinovito
3 Replies

7. Shell Programming and Scripting

Converting csh script to Pyhton

I am trying to call this python script tdarwin.py -nxz=23x35 and should take the -nxz and take the values 23 and 35 to two variables. But am getting the error "option -n not recognized" long_opts= try: optlist, args = getopt.getopt(sys.argv, "", long_opts) ... (2 Replies)
Discussion started by: kristinu
2 Replies

8. Shell Programming and Scripting

translate a short csh script to bash

Hi, I have a csh: set NODES = `cat $HOST_FILE` set NODELIST = $TMPDIR/namd2.nodelist echo group main >! $NODELIST foreach node ( $NODES ) echo host $node >> $NODELIST end @ NUMPROCS = 2 * $#NODES I am very frustrated to translate it to bash: NODES = `cat... (3 Replies)
Discussion started by: rockytodd
3 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Shell Programming and Scripting

Converting bash script to csh

Hi, I'm a beginner in scripting and I recently wrote a bash script that would've worked fine until I realized it needed to be written in csh. Could someone please show me how to correctly change the syntax from bash to csh in this script? Any help will be greatly appreciated. I can provide more... (4 Replies)
Discussion started by: Kweekwom
4 Replies
Login or Register to Ask a Question