using cp command inside nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using cp command inside nawk
# 1  
Old 04-08-2009
using cp command inside nawk

Hello

I have facing issue while using cp command inside nawk block.

Code:
#!/bin/ksh
my_name=$1
nawk  -v my_name1=$my_name 'BEGIN {
n = split(my_name1,names,":");
for (i=1;i<=n;i++)
{
print names[i];
cpcmd = "cp " /tmp/test.txt" " ./sample
system(cpcmd)
}
exit
}'
exit 0

i'am getting below error

Code:
nawk: syntax error at source line 6
 context is
        cpcmd = "cp " >>>  /tmp/test. <<< txt " " ./sample
nawk: illegal statement at source line 6

Can anyone tell the correct syntax for copy the file inside awk block or what is the problem here in this code.

Thanks in advance
# 2  
Old 04-08-2009
I don't see if/how you're 'names[i]' for your 'cp', but......
Code:
cpcmd = "cp  /tmp/test.txt ./sample"
system(cpcmd)
close(cpcmd)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to avoid arguments inside Nawk command?

Hi, Here is my command print $2 was meant to select the second column however, it is getting substituted with the second argument that was passed to the script. Can you please tell me how can I resolve this ? (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Substitute variable inside nawk

Hi, I need to set "prd" in the below command to a unix variable nawk '/^#/ {next} FNR==NR {prd;next} !($0 in prd)' So, this is what i did fname=prd // unix shell variable nawk -v fname=$fname '/^#/ {next} FNR==NR {fname;next} !($0 in fname)'But the value of fname i.e "prd" is not... (8 Replies)
Discussion started by: mohtashims
8 Replies

3. Shell Programming and Scripting

Linux Command Error for nawk command

Hi All We are migrating our projects from unix environment to linux. I tried running a install script which sets up my project, i.e. the directory structure and all. But in the middle of the script i started receiveing following error : nawk: command not found . So i need to know which... (1 Reply)
Discussion started by: vee_789
1 Replies

4. Shell Programming and Scripting

Reading input record from inside nawk

Hi friends, I have small query with reg to awk search pattern.. below is my sample file and code which i tried.. $ cat file.txt xxx,yyyyy,messageID,sha xxxx,errorcode,messageID,name in the above sample file - let assume I know the errorcode(2nd record) using which I want to... (2 Replies)
Discussion started by: Shahul
2 Replies

5. Shell Programming and Scripting

Help to use NAWK command

Hi, I am using NAWK command to scan a file (test.txt) and to create new files based on the length of lines in the file test.txt. My requirement is I need to create test_good with records having line lenght less than 4 and to create test_bad with records having line lenght more than 4. I... (4 Replies)
Discussion started by: sbhuvana20
4 Replies

6. Shell Programming and Scripting

nawk command in Linux

I have a nawk command I use in Solaris.... ps -e -o comm | nawk -F'ora_pmon_' 'NF>1 {print $2}' However it seems that this command will not work in Linux. Linux bluemarron 2.6.16.54-0.2.12-smp #1 SMP Fri Oct 24 02:16:38 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux How could I do the same... (2 Replies)
Discussion started by: LRoberts
2 Replies

7. Shell Programming and Scripting

nawk command

what is this nawk doing? This is for solaris 10 with trusted extensions. Level=$(plabel | nawk 'BEGIN {FS='\*"} {PRINT $2}' ) it is supposed to return UNCLASSIFIED or whatever the zone label is. I understant $() execute this stuff, FS is field separator, print the 2nd field. Can... (1 Reply)
Discussion started by: djehres
1 Replies

8. Shell Programming and Scripting

case command inside awk/nawk

well I found lot of topics about awk..about if command in awk.. but I had to implement this: nawk -F"|" ' $47 ~ /0R0011/ { print > ("/home/user/M/MC.tmp" )} $47 ~ /0R0012/ { print > ("/home/user/M/DuSI.tmp" )} $47 ~ /0R0014/ { print > ("/home/user/M/FF.tmp" )} $47 ~ /0R0018/ { print >... (9 Replies)
Discussion started by: abdulaziz
9 Replies

9. UNIX for Dummies Questions & Answers

if within nawk command

I am trying to nawk through a file and if the 24.25.26 charachters in the file are "000" then print a line to a new file in one format, otherwise print a line in a different format. So far I have the following: nawk '/^1/ { if(substr($0,24,3) != 000)... (1 Reply)
Discussion started by: kshelluser
1 Replies

10. Shell Programming and Scripting

nawk command not found

Guys, i have an issue. I tried to ran a script and the whole thing was fine.. except when i came to a part, nawk ' BEGIN { machine=0 then system prompted that the nawk command was not to be found... I tried looking for the nawk command by using the "locate" command, and it returns... (5 Replies)
Discussion started by: 12yearold
5 Replies
Login or Register to Ask a Question