"unexpected end of file"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "unexpected end of file"
# 1  
Old 12-15-2011
"unexpected end of file"

%%%%%

Last edited by lucasvs; 05-01-2012 at 06:26 AM.. Reason: tidied code tag
# 2  
Old 12-15-2011
I can see two "do" but only one "done".

Btw. The exit line is probably not needed.

The awk lines are syntax errors. No clear what they are meant to do.

Last edited by methyl; 12-15-2011 at 07:04 AM..
# 3  
Old 12-15-2011
Thanks methyl for your reactivity !

So, you mean I should write this instead:
Code:
#!/bin/sh
for A in file.txt
do
egrep 'pattern1' ${A}.txt > ${A}_p1.temp
egrep 'pattern2' ${A}.txt > ${A}_p2.temp
done
for B in *_p*.temp
do
C=`basename ${B} .temp`
D=`cut -c 5-15 ${C}`
awk '{print '"${D}"',$0}' ${A}_p1.temp >> allresults.tab
awk '{print '"${D}"',$0}' ${A}_p1.temp >> allresults.tab
done

# 4  
Old 12-15-2011
Quote:
Originally Posted by lucasvs
#!/bin/sh
for A in file.txt
do
egrep 'pattern1' ${A}.txt > ${A}_p1.temp
egrep 'pattern2' ${A}.txt > ${A}_p2.temp
for B in *_p*.temp
do
C=`basename ${B} .temp`
D=`cut -c 5-15 ${C}`
awk '{print '"${D}"',$0}' ${A}_p1.temp >> allresults.tab
awk '{print '"${D}"',$0}' ${A}_p1.temp >> allresults.tab
done
exit;
1. egrep 'pattern1' ${A}.txt > ${A}_p1.temp --> Why have you given ${A}.txt? Is there a file by name "file.txt.txt"?
2. Why do you want to use for-loop for just one file "file.txt"?
3. Your first for-loop has a "do" but doesn't have a corresponding "done".
4. "exit" is really not required at the end because your script will end anyway. Use exit only if you want to abruptly terminate the program after some conditional check.
5. And please indent your script.


------------------------
Ah, methyl has already replied!

Last edited by balajesuri; 12-15-2011 at 07:03 AM.. Reason: Late reply
# 5  
Old 12-15-2011
@lucasvs regarding post #3. Is it safe to assume that your error message has gone?
Read post #4 first. There are useful comments about filenames and whether the first "for" is needed.

It is quite difficult to advise on a script which is failing unless we know what the script is intended to achieve. It always helps to post sample input (blotting anything confidential) , brief description of the process, sample expected output.
# 6  
Old 12-15-2011
Thank you for your comments.

I've just realised the second awk command has to look in ${A}_p2.temp (not p1).

Sorry methyl, I should have explained before.
Briefly, I try to:
1) find different patterns (more than 50 in total) in a text file (called file.txt),
2) extract them,
3) and put them in a same file called allresults.tab.

After adding the second "done", I don't have "unexpected end of file" error message.
Now it seems there is a problem with the cut command,
Code:
cut: file_p1: No such file or directory

and with the awk command:
Code:
awk: syntax error at source line 1
 context is
        {print  >>>  , <<< 
awk: illegal statement at source line 1

# 7  
Old 12-15-2011
Based on what we know so far the whole process can be boiled down to:
Code:
egrep "pattern1|pattern2" file.txt > allresults.tab

I am concerned about the use of the word "pattern" (which has special meaning in unix). Can we assume that you mean "string".

If the 50 strings were held in a file, you may wish to look at "grep -f".



Can't see what the "basename" , "cut" , "awk" lines are trying to achieve.

Last edited by methyl; 12-15-2011 at 08:55 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Error: "Syntax error; unexpected end of file"

Hello all, I am running a script to generate a report and mail it to an email address. When I am trying to validate whether the file is a 0 kb file, I am getting the below error. Error: "Syntax error; unexpected end of file" Any suggestions please? Code: #!/bin/sh .... (1 Reply)
Discussion started by: Pradeep_Raj
1 Replies

3. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies

4. Shell Programming and Scripting

Please identify "unexpected end of file" bug

This is a script I got off the web for transferring Safari's "reading list" to the Pocket app. I ran it in terminal with the command bash exportsafarireadinglist.sh and got syntax error: unexpected end of file. Thanks for any help! The code: #!/bin/bash # Script to export Safari's reading... (2 Replies)
Discussion started by: kdog126
2 Replies

5. Shell Programming and Scripting

Error"syntax error at line 15: `end of file' unexpected"

While i m running below code, it is giving me the error"syntax error at line 15: `end of file' unexpected". Pls let me know what is wrong here..i tried many ways, but no luck dbSID="SWQE" usrname="apps" password="Wrgthrk3" count=0 while do sqlplus $usrname/$password@$dbSID... (5 Replies)
Discussion started by: millan
5 Replies

6. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

7. Shell Programming and Scripting

Help with error "syntax error: unexpected end of file"

Hi Techies, can anyone please debug the following Script and let me know what is going wrong here. im getting the following error #!/usr/bin/bash # ############################################################################################## # # Variables # #... (2 Replies)
Discussion started by: mahi_mayu069
2 Replies

8. Shell Programming and Scripting

"Unexpected end of file" on a very simple script!!!

Well, this is a very crazy issue, and I'm scratching my head to find a solution. This is a simple code to tranfer a file, in my main script I need to add a conditional statement (IF/THEN) like the below example: #!/bin/bash if ; then ftp -inv "192.168.1.10" << EOFTP user... (8 Replies)
Discussion started by: Lord Spectre
8 Replies

9. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

10. Shell Programming and Scripting

"unexpected end of file" when Iīm use EOF inside block if

I have a trouble in my script when i use EOF inside block if. If i use EOF whitout block if I donīt have problem. Guys any ideas? Sorry for my terrible English. #!/bin/sh set -xv HOST='ftp.fiction.com.br' USER='fictionuser' PASS='fictionpass' FILE='ftpteste.txt' busca=`find... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies
Login or Register to Ask a Question