我有一个正在 Windows 计算机上处理的文本文件。bcp
在使用实用程序将数据从文件加载到数据库表之前,需要删除尾随制表符。
Bash 脚本中的以下命令删除了尾随选项卡:
sed 's/[\t]*$//' < ./input/raw.txt >> ./input/data.txt
Run Code Online (Sandbox Code Playgroud)
CR
但它将-转换LF
为LF
导致bcp
命令失败的原因。
为了努力保持CR
-LF
我尝试了这个:
sed 's/[\t]*$/$CR/' < ./input/raw.txt >> ./input/data.txt
Run Code Online (Sandbox Code Playgroud)
但这导致:
期望的结果是:
如何修改命令以获得所需的输出?
我正在编写一个 Git Bash 实用程序,它将项目文件夹从一个位置复制到另一个位置。用户可能希望将项目复制到多个目标,但每次执行脚本只允许一个位置。到目前为止的逻辑是这样的 -
#!/bin/bash
# declare and initialize variables
source="/z/files/development/xampp/code/htdocs/Project7"
targets[0]="/z/files/development/xampp/code/htdocs/test/$(date +'%Y_%m_%d')"
targets[1]="/c/users/knot22/desktop/temp_dev/$(date +'%Y_%m_%d')"
# display contents of variables to user
echo "source " $source
echo -e "\nchoice \t target location"
for i in "${!targets[@]}"; do
echo -e "$i \t ${targets[$i]}"
done
echo
# prompt user for a target
read -p "Enter target's number for this copy operation: " target
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。接下来我想编写一个if
语句来检查用户输入的值是否target
是targets
. 在 PHP 中它将是array_key_exists($target, $targets)
. Bash 中的等价物是什么?