Im bit stuck s in writing shell script which downloads the file from the SFTP server
Script first list the available files over server and check the today's file in the list.
if file available then transfer function gets called and file downloading starts.
iam able to list out the available files found the today's file in below format.
) to the variable by which transfer function gets initated.
so here i have the value in available_file_variable =
i need to cut only filename from the available file variable not file permission ,timestamp etc and set to the transfer_file means available file variable >>transfer_file.
how i can do it by cut or awk to set transfer_file = UAT.pVV.SID.VGL.D170506.T110027.AMA.BVS.FTP.DATA.gz
You could correct the variable, by using it like this:
But that will only work if the files on the ftp server never contain spaces..
Correctly parsing ls -l output can sometimes be surprisingly difficult, because it may vary because if it is younger or older than 6 months or maybe even the locale setting..
I think best would be to adjust the script so that ls -1 is used instead of ls -l (ls minus one vs. ls minus el).
Last edited by Scrutinizer; 05-07-2017 at 03:33 AM..
This User Gave Thanks to Scrutinizer For This Post:
What I meant was you could pass:
instead of
What I was trying to say is that this should work, if the file name does not contain spaces.
--
You could also change the command substitution to something like this:
or
Also, providing the file name does not contain space characters...
--
But best would be to adjust the script so that it only stores the file names in the file $listing_file, my suggestion was to use ls -1 rather than ls -l to produce $listing_file
This User Gave Thanks to Scrutinizer For This Post:
Well all you need once you got your ls -l output is a pipe with awk to get the 9th field: e.g. with ls -l ->
That will sometimes work with the right locale and if a time six months ago results in the same number of fields and if filenames do not contain spaces.
Otherwise it may fail.
It will also sometimes fail if owner or group name are too long, causing owner and group fields to "blend", which results in fewer fields than provisioned.
Parsing ls -l output is unreliable, unless the variability of the output is known precisely.
Last edited by Scrutinizer; 05-07-2017 at 07:37 AM..
This User Gave Thanks to Scrutinizer For This Post:
I am using : << cut / cut to comment out block of code.
Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines.
The "warning " is at last line of script.
done < results
169 echo "END read all positioning parameters"
170... (8 Replies)
I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Hello ppl
I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt
Now I have to join (paste in unix) this A2.txt with external file A3.txt to form
output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Hi,
First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong !
I am very new to UNIX scripting.
Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :-
Code :-
(Feb 7, 571 7:07:29 AM),... (4 Replies)
Hi,
I am working on one script..I am having files in the below format
file 1 (each line is separated with : delimeter)
SPLASH:SPLASH:SVN
CIB/MCH:MCH:SVN
Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Dears,
i want cut the lines from a log file. Example of the log file as follows..
May 27, 2011 5:54:51 PM com.huawei.ivas.utilities.sm.client.SMDeliverContrUtil isDeliverSM
FINE:
May 27, 2011 5:54:51 PM com.huawei.ivas.utilities.sm.client.SMUtil addSysUpMsgLog
INFO: . The message content... (1 Reply)
Dear All,
I have a requirement in which i have to load a file placed in FTP location onto my database. The process i'll follow is as below:
1) Get the files using FTP.
2) Create the desired load files as i have to load only 19 fields out of the 104 available in the file.
The fields i require... (7 Replies)
Hi
Can anyone what I am doing wrong while using cut command.
for f in *.log
do
logfilename=$f
Log "Log file Name: $logfilename"
logfile1=`basename $logfilename .log`
flength=${#logfile1}
Log "file length $flength"
from_length=$(($flength - 15))
Log "from... (2 Replies)