[Solved] Syntax error for awk in a loop

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Syntax error for awk in a loop
# 1  
Hammer & Screwdriver [Solved] Syntax error for awk in a loop

can some one please tell me what is the problem with my syntaxSmilie

I have 100 files in one folder
1. want to read each of the line by line
2. calculate their number of the words between the first word and the last word of each line
3. create file for each file with number of words between them instead of words for each line

for X in "$FILES"
	awk '{print NF-2}' $X > count/$X-new.txt 

and it gives the error
bash: count/word/*-new.txt: No such file or directory
but some who this is not working and I dont understand where the problem is Smilie
# 2  
what is the value of the variable ?


And do you have a folder called count inside the test directory ?
# 3  
no specific value ...

i might be doing this wrong ... I want to create documents with either the same name or something like previous name + new
not sure if i have done right

I have test folder with two folders of data and count
data is the one with 100 files in it and I was running the code when i was on test

i have changed the folders around but still get the same things
# 4  
try this..
for X in "$FILES"
    new_name=$(basename $X)    
    awk '{print NF-2}' $X > count/${new_name}_new.txt 

This User Gave Thanks to itkamaraj For This Post:
# 5  
Thanks for the reply

I get the following error

basename: extra operand `data/this-that.txt'
Try `basename --help' for more information.
and it only creates one file with combined count and 100 files

Am i missing a loop for that?
# 6  
can you post your script
# 7  

now that change to yours I have

for X in "$FILES"
    names=$(basename $X)    
    awk '{print NF-2}' $X > count/${names}.txt 

I have 100 files in WORD
and want the same 100 files in COUNT but number of words instead of the words itself

and i get the following error

basename: extra operand `word/this-that.txt'
Try `basename --help' for more information.

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

Test Your Knowledge in Computers #615
Difficulty: Medium
You can specify multi-line strings using triple quotes in Python.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Syntax error in for loop

I am using simple for loop, but getting syntax error when I run the code code #!/bin/ksh pls enter number read n for(i=1; i<=n; i++) do echo $i done syntax error + pls enter number + read n (5 Replies)
Discussion started by: stew
5 Replies

2. Shell Programming and Scripting

[Solved] While loop error when add sqlplus command

Hi gurus, I hit a block when write the script. I need do while loop, in the loop I have code below. sqlplus -s abc/abc@abc <<EOF spool testwhile select * from dual; spool off exit; EOF when I run script with only this code, it works fine. if I add code as below: #!/bin/ksh ... (5 Replies)
Discussion started by: ken6503
5 Replies

3. Shell Programming and Scripting

[Solved] FOR loop / IF statement returning error

The code at the bottom is a simplified example of what we have. If I use the following: && echo "echo failed" $? returns 1 When I use if ; then echo "echo failed" ; fi $? returns 0 Does anyone know what's wrong with this? Using AIX 6.1 and KSH for NUM in 1 2 3 do ... (5 Replies)
Discussion started by: jfxdavies
5 Replies

4. Shell Programming and Scripting

[Solved] 0403-057 Syntax error for if statement

I am getting the following error when I am running a script in ksh when trying to execute an if statement comparing two numerical values tstmb.sh: 1.5321e+08: 0403-057 Syntax error Below is my code snippet. #!/bin/ksh set -x TODAY=$(date +%y%m%d) for file in $(ls -rt *.log | tail... (11 Replies)
Discussion started by: kiran1112
11 Replies

5. Shell Programming and Scripting

[Solved] 0403-057 Syntax error `<' is not matched

curr_time=`date +%Y%m%d%H%M` curr_date=`date +%Y%m%d` zero=0 script_path="/home/wccuser1/wcc/Scripts/bulk_file_ftp" file_dir="/home/wccuser1/wcc/Bulk_Files" todays_file_count=`ls -ltr | grep $curr_date | awk '{print $9}' | wc -l` todays_file=`ls -ltr | grep $curr_date | awk '{print $9}'` if... (5 Replies)
Discussion started by: gagandeep
5 Replies

6. Shell Programming and Scripting

IF loop syntax error

I am trying to run a menu option though IF loops. I keep getting errors not allowed the menu to be processed correctly. Currently it will accept the first 2 statements but then crash on the 3rd. The 2nd and 3rd have the same syntax, so I do not understand why it breaks. #!/bin/bash while... (4 Replies)
Discussion started by: Ironguru
4 Replies

7. Shell Programming and Scripting

Syntax error: Bad for loop variable

I'm getting an error while running this script. Need help. set -x verbose #echo on clear #clear the screen USERNAME="bbb" PASSWORD="password" SERVER="" WAIT_TIME=300 FILE_PATH="/home/users/xxx/MMM" # local directory to pickup *.dat file REMOTE_PATH="/Drop_off/xxx/yyy" #... (17 Replies)
Discussion started by: clgz2002
17 Replies

8. Shell Programming and Scripting

Syntax error: Bad for loop variable

Hi Can any one help, I'm trying to run a script that beeps out the ip address from the PC internal speaker with the following script. It keeps throwing the error "Syntax error: Bad for loop variable" on line 16. I know its picking up the IP ADDRESS correctly. Any ideas on whats wrong. I'm... (3 Replies)
Discussion started by: dman
3 Replies

9. Shell Programming and Scripting

Problems with syntax in a loop (AWK)

Hi guys, I'm trying to loop through a number of files that is set by whatever is in a field. eg. The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited. I thought simple, count the number of fields in the field and then loop... (1 Reply)
Discussion started by: Peejay
1 Replies

10. Shell Programming and Scripting

syntax error in while loop

Hi, I have the following script (compile_mercury) and I get this error: I have no idea why...and I have written this script completely in linux (bash) and not in windows. **************** ./compile_mercury: line 136: syntax error near unexpected token `done' ./compile_mercury: line 136:... (1 Reply)
Discussion started by: habzone2007
1 Replies

Featured Tech Videos