简体   繁体   English

将文件拆分到新文件夹

[英]Splitting files into a new folder

I am writing my first script so forgive me for my beginners mistakes. 我正在写我的第一个脚本,所以请原谅我的初学者错误。 I've been looking all over stack overflow and have not found anything that helps me with this problem. 我一直在寻找整个堆栈溢出,还没有找到任何可以帮助我解决这个问题的东西。

The script will use WinSCP to access folders in a Raspberry Pi and split a file that has become too large. 该脚本将使用WinSCP访问Raspberry Pi中的文件夹,并拆分一个太大的文件。 Then it will copy the sub files over to a Desktop using WinSCP again. 然后它将再次使用WinSCP将子文件复制到桌面。 We know how to split the file and how to move things over to WinSCP, but since we cannot control the sub file names, we thought it would make more sense to store them in a folder and move that over. 我们知道如何分割文件以及如何将其移动到WinSCP,但是由于我们无法控制子文件名,因此我们认为将它们存储在文件夹中并将其移动会更有意义。

This is what I have thus far: 到目前为止,这是我所拥有的:

#!/bin/bash
# Data Collector Script
mkdir $output
mv split -l 20000 helloworld.txt output //This is the line where I get stuck

Is there a way I can directly split the files into an output file? 有没有一种方法可以将文件直接拆分为输出文件? I would move them manually but the file names are random. 我会手动移动它们,但是文件名是随机的。

Try this: 尝试这个:

split -l 20000 helloworld.txt output/x

Reference: http://linux.die.net/man/1/split 参考: http : //linux.die.net/man/1/split

@Rob has the answer, and here's a small script using it that tries to defend against BASH's deficiencies as a programming language: @Rob有答案,这是一个使用它的小脚本,它试图抵御BASH作为编程语言的缺陷:

#!/bin/bash

# make BASH fail on errors and unset variables
set -eu

output='output_dir'
file_to_split="helloworld.txt"

# make the directory
# -p means no errors if the directory is there already
mkdir -p "${output}"

split -l 20000 "${file_to_split}" "${output}/${file_to_split}."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM