For loop - unexpected token `do


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop - unexpected token `do
# 8  
Old 08-28-2015
Code:
-bash-4.1$ uname -a
Linux serername  x86_64 x86_64 GNU/Linux
-bash-4.1$ type bash date sh
bash is /bin/bash
date is /bin/date
sh is /bin/sh
-bash-4.1$ ls -l /bin/bash /bin/date /bin/sh
-rwxr-xr-x 1 root root 938832 Jul  9  2014 /bin/bash
-rwxr-xr-x 1 root root  59392 Oct 17  2014 /bin/date
lrwxrwxrwx 1 root root      4 Mar  4  2015 /bin/sh -> bash
-bash-4.1$

Code:
Code:
-bash-4.1$ date +%Y-%m-%d --date "1 day ago"
2015-08-27
-bash-4.1$

---------- Post updated at 04:34 AM ---------- Previous update was at 03:45 AM ----------

I managed to get output now. THere was a line feed issue earlier.

My output file (output_file.txt) Contains filenames alongwitH direCtories like below.

/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-27_tmptcmsaslva2_19142.log

HoweVer I need only tHe filename. How to do tHat?

I also need a log file for te sript exCeution. wHat would be tHe Command for tHat?
# 9  
Old 08-28-2015
Use bash's parameter expansion / Remove matching prefix pattern: ${parameter##word}

What do you want to log (entire execution / all stdout/stderr / extra logging output)?
# 10  
Old 08-28-2015
I want tHe Command to Capture entire exeCution in log.

Kindly giVe Command witH example to remoVe matCHing prefix as I'm not sure write a Command wit your inputs.

THanks.
# 11  
Old 08-28-2015
Why are so many letters within a word in caps? (your first posts were good)
Please try to write proper grammer -> Nobody is perfect and many here are not native english speakers/writers/readers -> and i know of no language having capital letter within a word.

If that happens by accident, please clean your keyboard.

Thank you.
# 12  
Old 08-28-2015
To just produce the filenames, try:
Code:
cd /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs
for i in "SASApp_STPServer_$(date +%Y-%m-%d --date "1 day ago")_tmptcmsaslva2_"*.log
do	echo "$i"
done > output_file.txt

or, assuming that your list of files won't exceed ARG_MAX limits, just:
Code:
cd /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs
printf '%s\n' "SASApp_STPServer_$(date +%Y-%m-%d --date "1 day ago")_tmptcmsaslva2_"*.log > output_file.txt


Last edited by Don Cragun; 08-28-2015 at 03:47 PM.. Reason: Put the * back in the pattern.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Syntax error near unexpected token `('

detect_mouse_mvt.sh /home/andy/bin/detect_mouse_mvt.sh: line 4: syntax error near unexpected token `(' /home/andy/bin/detect_mouse_mvt.sh: line 4: `fh = file('/dev/input/mice')' #!/bin/bash # # fh = file('/dev/input/mice') while True: fh.read(3) print 'Mouse... (15 Replies)
Discussion started by: drew77
15 Replies

2. UNIX for Beginners Questions & Answers

Syntax error near unexpected token 'do'

Hello all, Please i have this command i used to zip different files in differents directory, but i have an error. Note that when i run the command in one directory it works fine. /X5/WORK/BGH/INV/REG/pdf/SEND/BGH12523/1/*.fo /X5/WORK/BGH/INV/REG/pdf/SEND/BGH24523/1/*.fo... (3 Replies)
Discussion started by: gillesi
3 Replies

3. Shell Programming and Scripting

Syntax error near unexpected token '('

I tried to execute the code but I got this error ./Array.c: line 9: syntax error near unexpected token '(' ./Array.c: line 9: ' nvals = get_data(a,MAXARRAY);' and #include<stdio.h> #define MAXARRAY 1000 main() { int a, nvals; nvals =... (7 Replies)
Discussion started by: sgradywhite
7 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

5. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

6. Shell Programming and Scripting

Unexpected Token Error `;;'

Hello all, Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it. 7 ##******************************************************************************************************* 8 ## ********** FUNCTION USAGE *********** ... (13 Replies)
Discussion started by: raghunsi
13 Replies

7. Shell Programming and Scripting

Syntax error near unexpected token `done'

Hi all, Here is a simple script that is working in one server and is giving a syntax error in other server. Can somebody help me ? #!/bin/bash # ftp files done < $file errors: I tried..with no success: if ; then (21 Replies)
Discussion started by: Lenora2009
21 Replies

8. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

9. Shell Programming and Scripting

sh syntax error unexpected token done

I'm getting the following error: line 21: syntax error near unexpected token `done` line 21: `done` and I haven't been able to figure out why. Here is my code #!/bin/sh if ; then echo 'Usage: rename getexp/replStr ' exit 0 fi arg = $1 shift while ; do (5 Replies)
Discussion started by: NullPointer
5 Replies

10. Shell Programming and Scripting

While loop error: Unexpected token done

I have tried to implement a while loop into the code but upon running the following code i am getting the errors: ./Assigntest: line 42: syntax error near unexpected token `done' ./Assigntest: line 42: `done' The code is as follows: #!/bin/bash #Filename: Assignment Author: Luke... (9 Replies)
Discussion started by: warlock129
9 Replies
Login or Register to Ask a Question