[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
# 15  
Old 05-14-2009
Indeed, I hope you saw it works perfectly now! Only now I need to have an IF clause for the IP's where there's a folderlist for. See previous post.
Muchos gracias
# 16  
Old 05-14-2009
Maybe you can check this thread to get an idea how to use a loop within the ftp command:

https://www.unix.com/answers-frequent...transfers.html

Regards
# 17  
Old 05-14-2009
Quote:
Originally Posted by Franklin52
Maybe you can check this thread to get an idea how to use a loop within the ftp command:

https://www.unix.com/answers-frequent...transfers.html

Regards
FTP is not really a problem here, though I will check out the thread. But what I would need here is:

Code:
awk '{ sub("\r$", ""); print }' ftpservers.txt > unixfile.txt
awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f];system("cat " a[f] "_folderlist.txt")}}' unixfile.txt 

If _folderlist.txt exists then
 ftp myserver 
 user UN PW
 **transfer folders** 
else 
 **show: No such file or directory (or something like that)**
fi
done

Thanks in advance

Last edited by laurens; 05-14-2009 at 07:20 AM..
# 18  
Old 05-14-2009
You can give this a try. The awk command prints the ipaddress and the filename separated by a space.
The 1st while loop reads the ipaddress and the filenames and the 2nd loop gives the contents (directories) of the files.

Code:
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
    # log in with $ipaddress
    # copy $dir .....
  done < $flist
done

Hope this helps.
# 19  
Old 05-14-2009
Thanks a bunch Franklin, You're a genious! That's exactly what I need. I'm now trying to establish an FTP connection by using $ipaddress and transfer the $dir 's.
I'll let you know when I'm that far

Regards,
Laurens

EDIT: one more thing, how can I get all .txt files at once.
Code:
ftp -n -v immserv1.xx.xx.be << EOT
ascii
user U/N P/W
prompt
cd BACKUP
###get *.txt###
ls
EOT

Something like get *.txt , but that ain't working. Thx

Last edited by laurens; 05-14-2009 at 09:03 AM..
# 20  
Old 05-14-2009
Quote:
Originally Posted by laurens
Thanks a bunch Franklin, You're a genious! That's exactly what I need. I'm now trying to establish an FTP connection by using $ipaddress and transfer the $dir 's.
I'll let you know when I'm that far

Regards,
Laurens

EDIT: one more thing, how can I get all .txt files at once.
Code:
ftp -n -v immserv1.xx.xx.be << EOT
ascii
user U/N P/W
prompt
cd BACKUP
###get *.txt###
ls
EOT

Something like get *.txt , but that ain't working. Thx
Try it with mget.

Regards
# 21  
Old 05-14-2009
Worked like a charm... A true genius, like I said. Thx
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