首页 \ 问答 \ 降序排序非常小的数字(Descending order sort for very small numbers)

降序排序非常小的数字(Descending order sort for very small numbers)

我有我的输入文件:

Helguson 1.11889675673e-06
CAPTION_spot 1.37407731642e-07
Earning 1.20657023177e-06
340km 6.82228429758e-07
Mortimer 3.08700799033e-07
yellow 6.26784196571e-06
four 0.000271117940104
Pronk 5.79848408861e-07
jihad 3.25632057648e-07

我想按第二列的降序排序,因此,我尝试使用linux命令:

sort -k2 -nr input.txt > output.txt

我的输出生成为:

340km 6.82228429758e-07
yellow 6.26784196571e-06
Pronk 5.79848408861e-07
jihad 3.25632057648e-07
Mortimer 3.08700799033e-07
CAPTION_spot 1.37407731642e-07
Earning 1.20657023177e-06
Helguson 1.11889675673e-06
four 0.000271117940104

它没有正确排序。 怎么解决这个? 请帮忙。


I have my input file as :

Helguson 1.11889675673e-06
CAPTION_spot 1.37407731642e-07
Earning 1.20657023177e-06
340km 6.82228429758e-07
Mortimer 3.08700799033e-07
yellow 6.26784196571e-06
four 0.000271117940104
Pronk 5.79848408861e-07
jihad 3.25632057648e-07

I want to sort in descending order of the second column and hence, I tried using the linux command:

sort -k2 -nr input.txt > output.txt

My output is generated as:

340km 6.82228429758e-07
yellow 6.26784196571e-06
Pronk 5.79848408861e-07
jihad 3.25632057648e-07
Mortimer 3.08700799033e-07
CAPTION_spot 1.37407731642e-07
Earning 1.20657023177e-06
Helguson 1.11889675673e-06
four 0.000271117940104

It is not sorting properly. How to resolve this? Please help.


原文:https://stackoverflow.com/questions/33638996
更新时间:2022-12-14 16:12

最满意答案

这个功能内置在MsBuild for .Net项目中(在Microsoft.Common.Targets中搜索PostBuildEvent,也可以在这里看到),这里是一个简化版本。 原则是在构建之前获取输出文件的时间戳,在构建之后获取另一个时间戳,然后比较它们。 如果它们是相同的,显然没有真正构建。 这个逻辑有一个可能的插入点的镜像,在这里我只选择了链接阶段应该做得很好:

<Target Name="GetTimeStampBeforeLink" BeforeTargets="Link">
  <ItemGroup>
    <ProjectOutputFiles Include="$(TargetPath)" />
  </ItemGroup>
  <PropertyGroup>
    <OutputTimeStampBeforeLink>%(ProjectOutputFiles.ModifiedTime)</OutputTimeStampBeforeLink>
  </PropertyGroup>
</Target>

<Target Name="GetTimeStampAfterLink" AfterTargets="Link">
  <PropertyGroup>
    <OutputTimeStampAfterLink>%(ProjectOutputFiles.ModifiedTime)</OutputTimeStampAfterLink>
    <OutputFilesModified Condition="'$(OutputTimeStampBeforeLink)' != '$(OutputTimeStampAfterLink)'">True</OutputFilesModified>
  </PropertyGroup>
</Target>

您可以将此代码直接插入到项目文件中,但更好的方法是将其保存在单独的文件中,以便您可以通过将其导入到任何您想要的位置来重复使用if。 您还可以通过添加到ProjectOutputFiles ItemGroup来添加要检查的ProjectOutputFiles

现在剩下的就是禁用PostBuildEvent。 MsBuild已经有了一个机制,因为postbuild事件调用是以一个名为PostBuildEventUseInBuild属性为条件的,所以如果没有修改输出文件,我们将其设置为false:

<Target Name="DisablePostBuildEvent" AfterTargets="GetTimeStampAfterLink">
  <PropertyGroup>
    <PostBuildEventUseInBuild Condition='"$(OutputFilesModified)' != 'True'">false</PostBuildEventUseInBuild>
  </PropertyGroup>
</Target>

This functionality is built-in in MsBuild for .Net projects (search for PostBuildEvent in Microsoft.Common.Targets, also see here), here is a simplified version. The principle is you get a timestamp of your output file(s) before the build, and another one after the build, then compare them. If they are the same, obviously nothing was really built. There's a miriad of possible insertion points for this logic, here I just picked the link stage which should do just fine:

<Target Name="GetTimeStampBeforeLink" BeforeTargets="Link">
  <ItemGroup>
    <ProjectOutputFiles Include="$(TargetPath)" />
  </ItemGroup>
  <PropertyGroup>
    <OutputTimeStampBeforeLink>%(ProjectOutputFiles.ModifiedTime)</OutputTimeStampBeforeLink>
  </PropertyGroup>
</Target>

<Target Name="GetTimeStampAfterLink" AfterTargets="Link">
  <PropertyGroup>
    <OutputTimeStampAfterLink>%(ProjectOutputFiles.ModifiedTime)</OutputTimeStampAfterLink>
    <OutputFilesModified Condition="'$(OutputTimeStampBeforeLink)' != '$(OutputTimeStampAfterLink)'">True</OutputFilesModified>
  </PropertyGroup>
</Target>

You can insert this code right into your projectfile, but a better idea is to save it in a seperate file so you can reuse if for other projects by importing it wherever you want it. Also you can add files to check by adding to the ProjectOutputFiles ItemGroup.

Now all is left is disabling the PostBuildEvent. MsBuild already has a mechanism for that since postbuild event invokation is conditional on a propery named PostBuildEventUseInBuild, so we set this to false if output files are not modified:

<Target Name="DisablePostBuildEvent" AfterTargets="GetTimeStampAfterLink">
  <PropertyGroup>
    <PostBuildEventUseInBuild Condition='"$(OutputFilesModified)' != 'True'">false</PostBuildEventUseInBuild>
  </PropertyGroup>
</Target>

相关问答

更多
  • 刚刚在这里发现你的问题,因为它也发生在我身上。 这是我所做的,希望能够解决/帮助找到问题。 删除了所有.suo 终止IIS Express 关闭VS2013并重新打开 打开你的项目并尝试启动它(F5) 你的web.config文件可能有错误。 对我来说,这是一个在那里两次。 修复了web.config文件,保存和繁荣,错误消失了。 希望它也能解决你的情况。 I just figured it out. In my web.config, I had the following in ...
  • 嗯,不,它没有运行。 如果你想绝对确定那么只是生成一个故意的构建错误: exit /b 1 请注意,您没有使用相同的构建设置,您已将VS2010配置为更详细。 工具>选项>项目和解决方案>构建和运行> MSBuild项目构建输出详细程度。 你已经将VS2010设置为“正常”但VS2013设置为“最小”。 所以你想要为VS2013改变它,这样你就可以得到你习惯的东西了。 只要注意VS2013中一个非常烦人的错误,我已经失去了无数分钟的生命。 使用“项目”>“属性”更改设置时,它并不总是显示您在工具栏中选择 ...
  • 因此,Visual Studio 2013附带了MSBuild的新版本,即MSBuild 12.0。 安装后,它会更改路径,以便默认使用新版本。 看起来你的解决方案使用visual studio 2012编译,你可以指定msbuild.exe的完整路径,例如 C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild“path \ solution.sln”/ property:Configuration = Debug 或者通过在执行msb ...
  • 在联系Microsoft的朋友后,他建议修复Data Tools安装 http://go.microsoft.com/fwlink/?linkid=393521&clcid=0x409 那就解决了。 谢谢Chuck! After contacting a friend at Microsoft, he suggested repairing the Data Tools install at https://docs.microsoft.com/en-us/sql/ssdt/download-sql-ser ...
  • 在尝试对项目文件进行各种更改后,我发现从本机C ++项目中删除以下行然后允许正确加载解决方案中的所有项目。 10.0.10069.0 但是,加载后我发现由于错误我无法构建本机项目: 错误MSB8020:找不到v140(Platform Toolset ='v140')的构建工具。 即使vcxproj指定ToolsVersion="14.0" ,似乎Visual Studio 2013将使用12.0用于C ++项目 ...
  • 我继承了这个项目,它有几个配置(ANSI Debug / Release和Unicode Debug / Release)。 由于我只针对Unicode,因此我手动从sln和vcxproj文件中删除了这些部分。 考虑到这一点,Visual Studio为不同的配置显示不同的选项后变得更加清晰。 切换到所有配置选项并从其他部分删除后,我可以进行计算运行。 xcopy仍然失败了一段时间,因为当链接器中的OuputFile选项更改为调试配置的后缀“_Debug”时, $(TargetPath)无法正确解析。 这一 ...
  • 这个功能内置在MsBuild for .Net项目中(在Microsoft.Common.Targets中搜索PostBuildEvent,也可以在这里看到),这里是一个简化版本。 原则是在构建之前获取输出文件的时间戳,在构建之后获取另一个时间戳,然后比较它们。 如果它们是相同的,显然没有真正构建。 这个逻辑有一个可能的插入点的镜像,在这里我只选择了链接阶段应该做得很好:
  • 对于问题1,请使用属性MSBuildBinPath 对于问题2,使用属性OutputPath (C#或VB项目) OutputFile="$(OutputPath)Foo.txt" For question 1, use property MSBuildBinPath For question 2, use property OutputPath (C# or VB projects) OutputFile="$(OutputPath)Foo.txt"
  • 在GitHub上有一个正在进行中的VS2013二进制文件的工作: https : //github.com/cinder/Cinder/tree/boost_155 另请参阅Cinder论坛上的这些相关论坛帖子,我建议在这里提出这类问题,以便更快地回复: https://forum.libcinder.org/topic/cinder-8-5-0-with-vs2013-and-boost-1-55-0 https://forum.libcinder.org/topic/contribute-now-lat ...
  • 您也可以根据构建过程中选择的配置来执行此操作。 对于CI,您应该始终使用“Release”或“Production”(您可以定义自己的) After much searching for a simple solution to this problem I didn't find one and ended up comin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)