[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
# 8  
Old 05-13-2009
As a matter a fact, yes! This is what I get -exactly- :
Code:
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt
_folderlist.txt

I guess for each IP it finds it gives a _folderlist.txt output... (?)

btw, I already have this piece of code that gives me the IP's back

HTML Code:
ftp -n -v immserv1.xx.xx.be << EOT
ascii
user UN password
prompt
cd BACKUP
get ftpservers.txt
ls
EOT
iplist=$(sed -n 1~3p ftpservers.txt)
for LINE in $iplist; do

     echo "$LINE"
#     ping -c 1 $LINE

done
This is step one. Next step is to display the folders that match with the IP's _folderlist. I've added a printscreen.
[bash] jump from one txt file to another-linsxqjpg

Last edited by laurens; 05-13-2009 at 01:10 PM..
# 9  
Old 05-13-2009
That's why I'm confused, this is the ouput I get:

Code:
$ cat file
80.xx.xx.76
ftpmac28
passO#lanL
212.xx.xx.52
ftpmac28
passO#lanL
212.xx.xx.61
ftpmac28
passO#lanL
212.xx.xx.62
ftpmac28
passO#lanL
212.xx.xx.17
ftpmac28
passO#lanL
212.xx.xx.10
ftpmac28
passO#lanL
212.xx.xx.75
ftpmac28
passO#lanL
$ awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f] "_folderlist.txt"}}' file
212.xx.xx.62_folderlist.txt
212.xx.xx.17_folderlist.txt
212.xx.xx.10_folderlist.txt
212.xx.xx.75_folderlist.txt
80.xx.xx.76_folderlist.txt
212.xx.xx.52_folderlist.txt
212.xx.xx.61_folderlist.txt

Have I missed something?
# 10  
Old 05-13-2009
Code:
awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f] "_folderlist.txt"}}' ftpservers.txt

This was in my bash script and the output of it was in my previous post. It would be weird I have a different output?

At the moment I don't have access to the servers, I will try again tomorrow. Can you maybe suggest a bash solution for the second step (concerning the _folderlists)? I will try it next thing tomorrow. Thx in advance

Regards,
Laurens
# 11  
Old 05-13-2009
This should give you the filenames and contents of the files:

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

The output should be like:

Code:
212.124.56.75
docshop.xx.be\files
extranetdocshop.xx.be\files
fleet.xx.be\doccshop\files
212.124.56.76
212.124.56.101
project.xx.be\html\upload
project.xx.be\html\attachement
212.124.56.113

# 12  
Old 05-13-2009
Thanks! I will try that asap and report to you
# 13  
Old 05-14-2009
Darned... It gives me this output for every IP address.
Code:
80.xx.xx.96
_folderlist.txt: No such file or directory
80.xx.xx.146
_folderlist.txt: No such file or directory
212.xx.xx.172
_folderlist.txt: No such file or directory
...etc...

I made a new script with only this inside:
Code:
awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f];system("cat " a[f] "_folderlist.txt")}}' ftpservers.txt

EDIT: I found it! There had to be a conversion from a windows txt format to unix txt format first, which I achieved like this
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

Now I would need something like an IF clause, if there is a folderlist I have to transfer the files via FTP. What isn't a problem, it's only the if clause...

Thanks!
Laurens

Last edited by laurens; 05-14-2009 at 06:03 AM..
# 14  
Old 05-14-2009
Really weird, I've tested this command on a Debian and on a HP Unix system , it works properly on both systems with an echo command so it should work with a cat command. With the given input file I get this:
Code:
$ awk 'NR%3==1{a[++i]=$0}END{for(f in a){print a[f];system("echo " a[f] "_folderlist.txt")}}' file
212.xx.xx.52
212.xx.xx.52_folderlist.txt
212.xx.xx.61
212.xx.xx.61_folderlist.txt
212.xx.xx.62
212.xx.xx.62_folderlist.txt
212.xx.xx.17
212.xx.xx.17_folderlist.txt
212.xx.xx.10
212.xx.xx.10_folderlist.txt
212.xx.xx.75
212.xx.xx.75_folderlist.txt
80.xx.xx.76
80.xx.xx.76_folderlist.txt
$

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