# File Download from Sharepoint folder

**URL:** <https://community.unix.com/t/file-download-from-sharepoint-folder/367684>\
**Category:** Shell Programming and Scripting\
**Created:** [August 1, 2017, 10:57am UTC](https://community.unix.com/t/file-download-from-sharepoint-folder/367684 "2017-08-01T10:57:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![puttaiah](https://community.unix.com/letter_avatar/puttaiah/32/6_449c533f586939b6e5f246632a46421f.png) [@puttaiah](https://community.unix.com/u/puttaiah)\
**Post date:** [August 1, 2017, 10:57am UTC](https://community.unix.com/t/file-download-from-sharepoint-folder/367684/1 "2017-08-01T10:57:19Z")

</div>

Hi All,

Please let me know the simple script to download the latest .xlsx file from the share point folder.

I am using the CURL command and which is working fine if give the particular file name. But I have the list of files with the timestamp.'

Ex :

```nohighlight
Filename_07202017.xlsx
Filename_07102017.xlsx

```

I should pick only the latest one which is Filename\_07202017.

Thank you.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [August 1, 2017, 1:31pm UTC](https://community.unix.com/t/file-download-from-sharepoint-folder/367684/2 "2017-08-01T13:31:36Z")

</div>

```nohighlight
NAME=$(sort -r < list | head -n 1)

```

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [August 1, 2017, 2:11pm UTC](https://community.unix.com/t/file-download-from-sharepoint-folder/367684/3 "2017-08-01T14:11:11Z")

</div>

> [@corona688](#):
>
> ```plaintext
> NAME=$(sort -r < list | head -n 1)
> 
> ```

Since the year comes after the month and day in the timestamps in these filenames, the sort needs to be a little more complicated (and assuming that the filename prefix does not contains any other `_` s):

```plaintext
NAME=$(sort -r -t_ -k2.4,2.8 -k2.1,2.4 list | head -n 1)

```

assuming that there is only one filename before the underscore in your list. If there are multiple filename prefixes in your list, you'll need a loop something like:

```plaintext
last=
sort -t_ -k1,1 -k2.4,2.8r -k2.1,2.4r list | while IFS=_ read -r filename time
do	if ["$last" = "$filename"]
	then	continue
	fi
	curl other_parameters "$filename"_"$time"
	last="$filename"
done

```

Note that both of these (and the code suggested by Corona688) assume that `list` is the name of a file containing one line for each `.xlsx` file in your share point directory and that that line contains only that file's complete filename.

---

<div class="post-metadata">

**Author:** ![puttaiah](https://community.unix.com/letter_avatar/puttaiah/32/6_449c533f586939b6e5f246632a46421f.png) [@puttaiah](https://community.unix.com/u/puttaiah)\
**Post date:** [August 2, 2017, 3:24am UTC](https://community.unix.com/t/file-download-from-sharepoint-folder/367684/4 "2017-08-02T03:24:41Z")

</div>

> [@don cragun](#):
>
> Since the year comes after the month and day in the timestamps in these filenames, the sort needs to be a little more complicated (and assuming that the filename prefix does not contains any other `_` s):
> 
> ```plaintext
> NAME=$(sort -r -t_ -k2.4,2.8 -k2.1,2.4 list | head -n 1)
> 
> ```
> 
> assuming that there is only one filename before the underscore in your list. If there are multiple filename prefixes in your list, you'll need a loop something like:
> 
> ```plaintext
> last=
> sort -t_ -k1,1 -k2.4,2.8r -k2.1,2.4r list | while IFS=_ read -r filename time
> do if ["$last" = "$filename"]
> then continue
> fi
> curl other_parameters "$filename"_"$time"
> last="$filename"
> done
> 
> ```
> 
> Note that both of these (and the code suggested by Corona688) assume that `list` is the name of a file containing one line for each `.xlsx` file in your share point directory and that that line contains only that file's complete filename.

Thanks for the details . But when try with this it is giving error  
" sort: Cannot open list"

Please help me with this issue.

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [August 2, 2017, 3:36am UTC](https://community.unix.com/t/file-download-from-sharepoint-folder/367684/5 "2017-08-02T03:36:21Z")

</div>

Replace "list" with the name of the file containing

> [@puttaiah](#):
>
> the list of files with the timestamp.

that you have.
