[bash] jump from one txt file to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [bash] jump from one txt file to another
# 22  
Old 05-14-2009
Code:
ftp -n -v immserv1.xx.xx.be << EOT
ascii
user UN PW
prompt
cd BACKUP
mget *.txt
ls
EOT
awk '{ sub("\r$", ""); print }' ftpservers.txt > unixfile.txt
awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f], a[f] "_folderlist.txt"}}' unixfile.txt |
while read ipaddress flist
do
  while read dir
  do   
        ftp -n -v $ipaddress << EOT
        ascii
        user UN PW
        prompt
        get $dir
        EOT
  done < $flist
done
rm unixfile.txt

I get the error error: ./bash.sh: line 25: syntax error: unexpected end of file which, as it seems, is provoked by the >> EOT
The problem doesn't lay in the IP-addresses and the U/N & P/W's.
Any ideas? Thx in advance
# 23  
Old 05-14-2009
Place EOT at the begin of the line without leading spaces and if you have save the script with a windows editor, remove the carriage returns as you did or with tr:

Code:
tr -d '\r' < your_file > new_file

Regards
# 24  
Old 05-15-2009
Quote:
Originally Posted by Franklin52
Place EOT at the begin of the line without leading spaces and if you have saved the script with a windows editor, remove the carriage returns as you did or with tr:

Code:
tr -d '\r' < your_file > new_file

Regards
Thanks Franklin. Solved.
It's sometimes in the details...

Last edited by laurens; 05-15-2009 at 05:17 AM..
# 25  
Old 05-15-2009
Code:
...
EOT
awk '{ sub("\r$", ""); print }' ftpservers.txt > unixfile.txt
awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f], a[f] "_folderlist.txt"}}' unixfile.txt | 
while read ipaddress flist
do
  while read dir
  do
         if [ $dir == "" ]; then
      echo dir is empty
else
ftp -n -v $ipaddress <<EOT
ascii
user *hard-coded-UN* *hard-coded-PW*
prompt
get $dir
EOT

One of my last questions... most of it works for now(!) I'm impressed. Only, for the moment, my ftp- username & password are entered hardcoded. I need to take them out of my ftpservers.txt

As you already know, this file has this layout:
Code:
line 1 = IP-address
line 2 = FTP-user
line 3 = FTP-pwd
line 4 = IP-address
line 5 = FTP-user
... etc ...
line 33 = FTP-user
line 34 = FTP-pwd
line 35 = IP-address
line 36 = FTP-user
line 37 = FTP-pwd
#-END

Thanks in advance!

Regards,
Laurens
# 26  
Old 05-15-2009
Try something like:

Code:
...
awk '
NR%3==1{a[++i]=$0}
NR%3==2{u[++i]=$0}
NR%3==0{p[++i]=$0}
END{for(f in a){print a[f], u[f], p[f], a[f] "_folderlist.txt"}}' unixfile.txt | 
while read ipaddress user passwd flist
do
  # Do something with "$ipaddress" "$user" "$passwd" "$flist"
  # ....
done

Regards
# 27  
Old 05-18-2009
Hi Franklin Smilie

As I don't really see the bomen door het bos anymore in the bash script... I don't see where it went wrong now.
I adjusted the script like you advised:

Code:
...
EOT
awk '{ sub("\r$", ""); print }' ftpservers.txt > unixfile.txt
awk '
NR%3==1{a[++i]=$0}
NR%3==2{u[++i]=$0}
NR%3==0{p[++i]=$0}
END{for(f in a){print a[f], u[f], p[f], a[f] "_folderlist.txt"}}' unixfile.txt | 
while read ipaddress user passwd flist
do
  while read dir
  do
         if [[ $ipaddress =~ ^192\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
      echo "private IP - skipping"
else
ftp -n -v $ipaddress <<EOT
ascii
user $user $passwd
prompt
...

This is the output:
Code:
do
  while read dir
  do
        if [[ $ipaddress =~ ^192\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
          echo "private IP - skipping"
else
ftp -n -v $ipaddress <<EOT
        fi
  done < $flist
done
++ awk '
NR%3==1{a[++i]=$0}
NR%3==2{u[++i]=$0}
NR%3==0{p[++i]=$0}
END{for(f in a){print a[f], u[f], p[f], a[f] "_folderlist.txt"}}' unixfile.txt
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
./bash.sh: line 32: $flist: ambiguous redirect
++ read ipaddress user passwd flist
rm unixfile.txt
++ rm unixfile.txt

Thanks again
# 28  
Old 05-18-2009
I'm sorry for the mistake, adjust the awk code like this:

Code:
awk '
NR%3==1{a[++i]=$0}
NR%3==2{u[i]=$0}
NR%3==0{p[i]=$0}
END{for(j=1;j<=i;j++){print a[j], u[j], p[j], a[j] "_folderlist.txt"}}' unixfile.txt

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash incert line from 1.txt to 2.txt

i would like to insert a line from 2.txt into 1.txt between " and " or a way of adding to the end of each line " _01_ and have the numbers correspond to the line # 1.txt= foofoo "" _01_ foofoo "" _02_ foofoo "" _03_ foofoo "" _04_ 2.txt= ... (6 Replies)
Discussion started by: klein
6 Replies

2. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

3. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

4. UNIX for Dummies Questions & Answers

Write pid and command name to a txt file while executing a bash script

Hi All, Just have a requirement, I am executing a bash shell script, my requirement is to catch the pid and job name to a txt file in the same directory, is there anyway to do it? please help me out. Regards Rahul ---------- Post updated at 08:42 AM ---------- Previous update was at... (2 Replies)
Discussion started by: rahulkalra9
2 Replies

5. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

6. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

7. UNIX for Advanced & Expert Users

vimdiff jump to other file or switch windows

This took me quite awhile to find so I wanted to share this with other people. To switch windows in vimdiff or to navigate windows in vimdiff or to change windows in vimdiff try the following: The ":vertical" command can be inserted before another command that splits a window. ... (0 Replies)
Discussion started by: cokedude
0 Replies

8. Shell Programming and Scripting

bash script to sort a txt file

I am writing a script to write to and a sort txt file. After I sort the file I want to add 2 to each line of the file. My script thus far is #!/bin/bash cat > /ramdisk/home/stux/unsortedints.out COUNT=0 FILE =/ramdisk/home/stux/unsortedints.out for i in {1..100} do NUMBER = $ echo $NUMBER... (3 Replies)
Discussion started by: puttyirc
3 Replies

9. Shell Programming and Scripting

Jump to a specific place in a file?

If I cat a file And want to go to the first instance of a particular value - what command would I use? And then from that point where I jumped to search for another value - but only search from that point forward not before the file? Thanks~ (2 Replies)
Discussion started by: llsmr777
2 Replies

10. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies
Login or Register to Ask a Question