awk - System command not working


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - System command not working
# 1  
awk - System command not working

dear All,

my awk system command isn't working or rather I'm missing something in my command. Appreciated , if anyone can assist me what exactly I'm missing ??

Code:
awk ' /^[^#]/ {
>  c=split($3,a,"/") ;for(n=1; n<=c; ++n)
> {
> if (system("test -d" /home/cubedata/20120104/"$1"/"a[n]")) {
> print "exist"
> }
> else { print "doesn't exist" }
> }}'  /home/conf/folderlist.txt

# 2  
Remove the single quote in else { print "doesn't exist" } and try ..

If expected output is not coming, pls post error message or some sample content of folderlist.txt ..
# 3  
And the system command should be like:
Code:
if (system("test -d /home/cubedata/20120104/" $1 "/" a[n]))

# 4  
hello Jay,

i didn't get what do you mean by remove single quote around else command. As there are no single quote around it. could you be more precise on it.

there is no error poping up, as well as o/p is not also coming up instead it's giving me next line as if it's waiting for next input as soon as I hit enter after the filename .

Code:
folderlist.txt

# ParentFolder  environment_flag        SubFolders
triss                 1                            checksum
bookstructure    1
fx                    1                             checksum_GMDB

Code:
awk ' /^[^#]/ {                                                                           >  c=split($3,a,"/") ;for(n=1; n<=c; ++n)
> {
> if (system("test -d /home/cubedata/20120104/"$1"/"a[n])){
> print "exist"
> }
> else { print "doesn't exist" }
> }}'  /home/conf/folderlist.txt
>

@ frankilin

I already tried your suggested one too, but still I think somewhere I'm missing some quotes or paranthesis, that's why after hitting enter button system thinks there is some missing links. No clue where.
# 5  
Code:
awk -v Q="'" ' 
   /^[^#]/ {
      c=split($3,a,"/");
      for(n=1; n<=c; ++n) {
         if (system("test -d /home/cubedata/20120104/" $1 "/" a[n])) {
            print "exist"
         } else {
            print "doesn" Q "t exist" 
         }
      }
      }
'  /home/conf/folderlist.txt

# 6  
thanks aigles.
But during this mean time I did try other way , which works well btw noted your single quote , I will try this one too.

Code:
awk ' /^[^#]/ {
> c=split($3,a,"/") ;for(n=1; n<=c; ++n)
> {
> rc=system("test -d /home/cubedata/20120104/"$1"/"a[n])
> if (rc==0)
> print "/home/cubedata/20120104/"$1"/"a[n]"  exist"
> else
> print  "/home/cubedata/20120104/"$1"/"a[n]"  not exist"
> }}' /home/conf/folderlist.txt

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #152
Difficulty: Easy
In 1995, Novell transferred the Unix trademarks to the ACME Computing Company.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command not working as expected

Following one line of awk code removes first 3 characters from each line but when I run the same code on another linux platform it doesn't work and only prints blank lines for each record. Can anyone please explain why this doesn't work? (31 Replies)
Discussion started by: later_troy
31 Replies

2. Shell Programming and Scripting

Using sprintf and system command in awk

Hello Friends, I'm trying something hard (for me) to create a report script,normally the following script works: Echos are just for cosmetic touch, echo -n "\n-----\t----------\t-------------\t\t--------------\t\t--------\n COUNT\tEVENT_TYPE\tRESPONSE_CODE\t\tINTERNAL_ERROR\t\tFLOWNAME... (7 Replies)
Discussion started by: EAGL€
7 Replies

3. Shell Programming and Scripting

Awk: System command not working in awk

Hi, I have around 10 files in a folder in which I want to change the file format from tab(\t) to pipe(|) with some changes in the fields as well. Below is the code, while tmp file is getting generated but move command is not working, please help Following is the code awk -F"\t" '{print... (2 Replies)
Discussion started by: siramitsharma
2 Replies

4. Shell Programming and Scripting

awk command on .DAT file not working?

Hi All, I am trying to run awk command on .DAT file and it is not working. The same command is working on .txt file: Contents of the file ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT: HEADER|ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT... (10 Replies)
Discussion started by: sagar.cumar
10 Replies

5. Shell Programming and Scripting

AWK command working different in Linux

Hi All I have fired a command in linux table=`echo ${file_name} | awk '{FS="/"; print $NF}' | awk '{FS="."; print $1}'` where file_name has /data/ds/dpr_ebicm_uat/backfill/temp/etl_app_info.csv /data/ds/dpr_ebicm_uat/backfill/temp/etl_app_jobs.csv ... (10 Replies)
Discussion started by: vee_789
10 Replies

6. Shell Programming and Scripting

awk command not working from the shell script

Hi, When i run the below command i am able to get the output. awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0' abc.txt | awk '/END DSSUBRECORD/{exit}{print}' | awk '/Owner/{exit}{print}' | awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}' Output: Name "file_name", ... (5 Replies)
Discussion started by: onesuri
5 Replies

7. Shell Programming and Scripting

awk command not working

Hi all, Trying to write a script that reads a file and prints everything after a certain string is found to the end of the file. Awk is giving me an error and not sure why it doesn't work: # cat test_file Mon Nov 16 2009 16:11:08 abc def Tue Nov 17 2009 16:08:06 ghi jkl Wed Nov 18... (8 Replies)
Discussion started by: jamie_collins
8 Replies

8. Shell Programming and Scripting

system command within awk

I was trying commands within awk. i got stuck here. i take 2 files. cat input first second third fourth fifth sixth seventh eighth ninht tenthcat add *************** Nirbhay ***************i run the command awk '{ if ( NR == 5 ) { print system("cat add") "\n" $0 } else {... (4 Replies)
Discussion started by: nirbhay
4 Replies

9. Shell Programming and Scripting

awk system() command not working

I am using Sun Solaris 5.8 I am trying to run a system command such as ls and echo inside awk, but when I run the following code system echo is not displayed. bash-2.03$ ls | awk 'BEGIN { print "first print" system("echo system echo") print "second print" ... (1 Reply)
Discussion started by: rakeshou
1 Replies

10. Shell Programming and Scripting

can I pass awk variable to system command?

I wanna use a system function to deal with several data. So I use awk variable FILENAME to transfer the file directory to system command, but it does not work. I use a shell function "out_function" to deal with data and save the result in another directory with the same file name. How can I... (2 Replies)
Discussion started by: zhynxn
2 Replies

Featured Tech Videos