首页 \ 问答 \ 使用空格作为具有剪切命令的分隔符(use space as a delimiter with cut command)

使用空格作为具有剪切命令的分隔符(use space as a delimiter with cut command)

我想用空格作为分隔符与cut命令。

我可以用什么语法?


I want to use space as a delimiter with the cut command.

What syntax can I use for this?


原文:https://stackoverflow.com/questions/816820
更新时间:2023-10-06 20:10

最满意答案

TL;博士

不要将BETWEEN用于字符串

其中drink_name> ='G'和drink_name <'P';

为什么?

O有效地扩展了尾随空格以匹配列。 所以

'O                  '

在此之前

'Oh My Gosh'

所以你需要

where drink_name BETWEEN 'G' and 'OZ';

如果你有一种名为Ozymandias的饮料,那么这将无效。 所以:

where drink_name BETWEEN 'G' and 'OZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';

但是,我们可以安全地假设没有叫P和许多空间的饮料吗?
这是不可理解的。

select drink_name from easy_drinks
where drink_name BETWEEN 'G' and 'P';

显而易见的选择可能是仅使用LEFT比较第一个字母

select drink_name from easy_drinks
where LEFT(drink_name, 1) BETWEEN 'G' and 'O';

但这会阻止在drink_name上使用任何索引。


tl;dr

Don't use BETWEEN for strings

where drink_name >= 'G' and drink_name < 'P';

Why?

The O is effectivly expanded with trailing spaces to match the column. So

'O                  '

is before

'Oh My Gosh'

So you'd need

where drink_name BETWEEN 'G' and 'OZ';

If you have a drink called Ozymandias then this won't work. So:

where drink_name BETWEEN 'G' and 'OZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';

But, can we can safely assume that there is no drink called P and many spaces?
This is not understandable.

select drink_name from easy_drinks
where drink_name BETWEEN 'G' and 'P';

The obvious choice might be to compare only first letters using LEFT

select drink_name from easy_drinks
where LEFT(drink_name, 1) BETWEEN 'G' and 'O';

But this will prevent used of any index on drink_name.

相关问答

更多
  • TL;博士 不要将BETWEEN用于字符串 其中drink_name> ='G'和drink_name <'P'; 为什么? O有效地扩展了尾随空格以匹配列。 所以 'O ' 在此之前 'Oh My Gosh' 所以你需要 where drink_name BETWEEN 'G' and 'OZ'; 如果你有一种名为Ozymandias的饮料,那么这将无效。 所以: where drink_name BETWEEN 'G' and 'OZZZZZZZZZZZZZZZZ ...
  • 大家都知道,我设法在上述项目中实现了这一点。 所以,如果有人感兴趣,他/她可以在那里找到它。 Just so everyone know, I managed to implement this in the mentioned project. So if anyone's interested he/she can find it there.
  • START TRANSACTION; Select apples from fruit where apples = 'golden' FOR UPDATE; ... COMMIT; SELECT ... FOR UPDATE语句首先锁定行,然后将其返回给您。 任何试图同时对同一行做同样事情的人都会等待你的COMMIT或ROLLBACK ,然后他们会收到你所做的任何改变的行...... 如果您无意更改行,您只想确保没有其他人可以,那么您可以SELECT ... LOCK IN SHARE ...
  • 使用case-expression ,如下面的缩写示例所示: update table set color= case when black then "black" when red then "red" when blue then "blue" end; 这是一个平方米 Use a case-expression, as in this abbreviated example: update table set color= ...
  • 这是我为自己找到的解决方案。 未经修改,它只能在Rails 3(或更高版本)中使用。 在Tag模型中: scope :find_by_names, lambda { |names| unless names.empty? where("tags.name IN (#{Array.new(names.length, "?").join(",")})", *names) else where("false") end } 在问题模型中: scope :tagged_with ...
  • 你应该做的是: 获得独占的写锁 选择要处理的行 将其状态更改为“处理”(或“可用”以外的其他内容) 解锁桌子 完成对行的所有处理 更新行以将其状态更改回“可用” 这将允许其他进程同时处理其他行。 它使表保持锁定足够的时间,以防止它们尝试在同一行上工作。 What you should do is: Get an exclusive write lock Select the row you want to process Change its status to "processing" (or somet ...
  • 你想要什么被称为“检查约束”。 不幸的是,MySQL不支持它们。 好吧,它会让你定义它们,但它实际上不会检查它们。 本文讨论使用触发器实现相同的功能。 What you want is called a "CHECK constraint". Unfortunately, MySQL does not support them. Well, it will let you define them, but it won't actually check them. This article discusse ...
  • 在这种情况下使用JOIN而不是嵌套查询通常是有益的: SELECT sp.order_id FROM survey_product AS sp LEFT JOIN (SELECT order_id FROM survey_product WHERE product_id = 20) AS sp_t ON sp.order_id = sp_t.order_id WHERE sp_t.order_id IS NULL AND ...
  • 这应该工作: select distinct item, `desc` from table group by item, `desc` HAVING count(distinct data1) > 1 or count(distinct data2) > 1 or count(distinct data3) > 1 This should work: select distinct item, `desc` from table group by item, `desc` HAVING count( ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)