[20181212]bash shell 字符串 补零.txt

[20181212]bash shell 字符串 补零.txt


--//上午写bash shell脚本,遇到一个问题,字符串前面补零的问题.


$ echo $BASH_VERSION

3.2.25(1)-release


$ a='12345'

$ printf "%08s\n" $a

   12345


$ printf "%8s\n" $a

   12345


--//对于字符串%8s,%08s都是一样的,都是前面补充空格.

--//数值可以使用类似的方法补零.


$ a='12345'

$ printf "%08d\n" $a

00012345


--//奇怪的是我在windows下安装git,里面自带bash就是ok的.

$ a='12345'

$ printf "%08s\n" $a

00012345


--//实际上在linux下printf有2个命令.一个是shell内建的,一个是外部命令.

$ type -a printf

printf is a shell builtin

printf is /usr/bin/printf


--//看了文档感觉没用.

--//正好我的字符串原来是16进制值.


$ a=0x12345

$ printf "%08x\n" $a

00012345


--//真要实现字符串前面补零,还是比较麻烦.


$ a=1a2b3c

$ printf "%08x\n" "0x"$a

001a2b3c

$ a=$(printf "%08s" $a | tr " " "0")

$ echo $a

001a2b3c


--//不知道还有什么好方法!!


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2285005/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-2285005/

C# 操作Excel的时候,出现"被呼叫方拒绝接受呼叫的异常"的解决方案(参考官方给出的解决方案) 首先官方有对这个错误给出解释和解决方案,连接如下: https://docs.microsoft.com/zh-cn/previous-versions/ms228772(v=vs.120)#%E5%8F%AF%E9%9D%A0%E7%BC%96%E7%A8%8B 简单来说,貌似是线程问题,我猜。。。 之前我尝试着在代码中添加 Thread.Sleep(1000); 来进行解决,这种办... 阅读详情

相关推荐

PLC与变频器联动控制:从开关量、模拟量到通讯的接线与编程实战

在工业自动化系统中,电机调速控制是核心需求之一,其关键在于实现可编程逻辑控制器(PLC)与变频器之间的可靠联动。其基本原理是通过PLC输出控制信号,由变频器接收并驱动电机按设定速度运行。这项技术的核心价值在于实现电机的软启停、精确调速与节能控制,广泛应用于风机、水泵、传送带及精密张力控制等场景。其中,开关量控制以其接线简单、抗干扰能力强的特点,成为基础且可靠的方案;而模拟量控制则能实现无级平滑调速,满足更高精度的工艺要求。本文以西门子、三菱等主流品牌为例,深入解析了这两种主流控制方式的硬件接线、参数设置与梯

729

shell 如何实现数字 字符串自动补0

https://www.cnblogs.com/wowchky/archive/2012/10/18/2729072.html shell如何实现 数字 字符串自动补零 awk shell对字符串进行处理,如果字符串长度不足5位,需要左边自动补0。 比如:123,自动补齐为00123 解决的方法有两种: 一种是shell的printf命令: 1 printf “05d\n” 123 另一种是使用awk: 1 echo 123 | awk ‘{printf(“05d\n”,$0)}’ ...

wgz7747147820的博客 2万+

Genesis物理引擎实战指南:轻量级确定性刚体仿真核心

刚体物理仿真作为机器人控制、嵌入式运动学验证和确定性游戏开发的基础技术,其核心在于数值稳定性、跨平台可复现性与约束求解精度。本文围绕线性互补问题(LCP)求解、半隐式欧拉积分和零依赖C++实现三大关键技术展开,解析如何在无GUI、低算力环境下构建可单步调试、帧级可控的确定性仿真系统。重点覆盖碰撞检测数学建模、关节局部坐标系绑定、质量-惯性张量一致性校验等工程落地关键点,适用于STM32、树莓派及教育实验场景。内容深度结合Genesis Physics Engine的源码实践,直击‘穿模’‘NaN’‘关节发软

ciya3282的博客 780

shell实现数位补齐

printf 命令可以按照指定的格式输出字符串或数字。其中,格式化字符串可以包含一个或多个转换说明符,用于指定输出的格式。其中,使用 % 符号和转换字符可以实现数位补齐。其中,%02d 中的 0 表示补齐的字符,2 表示补齐后的位数,d 表示输出的是一个十进制整数。使用 printf 命令实现数位补齐可以保证输出的数字格式规范,便于后续处理和分析。在 shell 中,可以使用 printf 命令实现数位补齐。输出结果为 0020。还可以结合awk实现。

liulanba的博客 8666

bash 循环生成nodeid(补0)

需求: 用一个脚本,按序列生成连续的ID号,启动模拟程序模拟多个节点 ID的样子是下面这样的,32个字符 A0000000000000000000000000000001 A0000000000000000000000000000002 启动程序用如下的命令: ./nodeA0000000000000000000000000000001 需要启动500个这样的终端。 ...

闲人的专栏 520

Cadence IC5141保姆级教程:Bandgap电路四大仿真(稳定性/噪声/启动/PSRR)完整流程与调参心得

本文提供Cadence IC5141中Bandgap电路的四大仿真(稳定性仿真、噪声仿真、启动仿真、PSRR仿真)的完整流程与调参心得。从原理图检查到ADE L配置,详细解析各仿真步骤的关键参数设置与优化策略,帮助工程师高效完成电路设计与性能调优。

weixin_30399821的博客 1048

shell如何实现字符串不足N位自动补零

printf "%04d\n" 99 解释:其中0表示不足为数用0补全,4表示补全到4为数

weixin_42891455的博客 3107

Xilinx SDK工程编译、链接、调试注意事项

1、添加工程 启动SDK时选取workspace,如下图所示: 对应的workpace文件夹中会生成如下几个文件: 如果当前workspace是首次加载工程,SDK会进入启动界面 点击Import Project,导入已有工程 点击Browse,添加工程路径,一个完整的工程包含一个bsp文件夹,一个HW文件夹,和一个src文件夹(添加C功能函数) 点击Fini...

Autumn_He的博客 1万+

shell脚本实现printf数字转换N位补零

shell脚本实现数字变量转换,N位补零功能。 #!/bin/bash name=$1 name=`echo $1|awk '{printf("%04d\n",$0)}'` echo "/home/pi/$name.mp4" omxplayer -o hdmi /home/pi/$name.mp4 --loop #omxplayer -o hdmi /home/pi/DJI-MAVIC-AIR2.mp4 --loop

Mark_md的博客 4288

linux awk shell 左补0

shell printf "%04d\n" 12 awk echo 12|awk '{printf("%03d\n",$0)}'

_木子_简单_ 9501

ECU-TEST笔记&使用技巧01

说明 1)所述均基于如下环境:ECU-TEST 8.0、Win10系统、NI Veristand 2018(HIL测试)。不排除因为版本及软件环境问题,所述方法不奏效或有更好的方法,欢迎交流,一起提高。 2)本博客以问答形式进行,所述问题均来自于实际测试(包括MIL、HIL测试)遇到的问题及需求,目的是提高测试效率和自动化测试序列的可维护性。 3)本博客尽量从测试方法及ECU-TEST原...

Eigrl的博客 1万+

C十:输出格式

  对于printf的输出格式,%后面跟的数字表示输出的位数.  %8表示输出8位,不足的,左边用空格补齐,类似的还有%-8,同样表示输出8位,不足的,右边用空格补齐。这种对格式的规定,不只是对输出字符串%s有效,对于其它输出格式也同样有效。还可以在%后面和8前面添加字符,表示输出8位,不足的,左边用指定字符补齐。 例如: printf("%8s",abcde),输出 abcde printf("...

m0_37564426的博客 545

腾讯混元3D世界模型2.0实战:从AI生成到Unity/UE引擎集成全指南

生成式AI正在重塑3D内容创作流程,其核心原理是通过大语言模型理解自然语言描述,并驱动多阶段生成流水线自动创建3D资产与场景。这项技术为游戏开发、虚拟仿真和数字孪生领域带来了革命性的效率提升,能够将传统需要数周的美术协作流程压缩至几分钟。在实际应用中,开发者需要掌握本地环境部署、模型推理优化以及生成资产与主流游戏引擎的集成工作流。本文以腾讯开源的混元3D世界模型为例,详细解析如何将AI生成的场景通过插件高效导入Unity和Unreal Engine,并针对光照烘焙、材质调整、性能优化等工程实践问题提供解决方

cnracht8153的博客 765

shell 字符串处理汇总(查找,替换等等)

字符串: 简称“串”。有限字符的序列。数据元素为字符的线性表,是一种数据的逻辑结构。在计算机中可有不同的存储结构。在串上可进行求子串、插入字符、删除字符、置换字符等运算。 字符: 计算机程序设计及操作时使用的符号。包括字母、数字、空格符、提示符及各种专用字符等。 一般字符的运算包括: 第一、找出字符或者字符串的类型,是数字、字母还是其他特定字符,是

lizhi200404520的专栏 7313

shell如何实现 数字 字符串自动补零 awk

shell对字符串进行处理,如果字符串长度不足5位,需要左边自动补0。 比如:123,自动补齐为00123 解决的方法有两种: 一种是shell的printf命令: 1 printf "05d\n" 123 另一种是使用awk: 1 echo 123 | awk '{printf("05d\n",$0)}' 转载于:https://www.cnblogs.com/wow...

weixin_30646315的博客 3506

FPGA中参数化SPI接口设计与Verilog实现

SPI(串行外设接口)作为嵌入式系统的核心通信协议,通过全双工、高速率特性在FPGA与Flash、ADC等外设交互中占据重要地位。参数化设计通过抽象时钟极性、数据位宽等可配置维度,采用分层架构实现硬件复用,显著提升开发效率。Verilog实现需重点处理跨时钟域同步和可配置帧结构,结合AXI总线集成与UVM验证方法学,可构建适应工业控制、物联网网关等场景的高可靠SPI解决方案。

ciya3282的博客 699

php sprintf 08x,PHP sprintf() 函数_程序员人生

PHP sprintf() 函数实例把百分号(%)符号替换成一个作为参数进行传递的变量:$number = 9;$str = "Beijing";$txt = sprintf("There are %u million bicycles in %s.",$number,$str);echo $txt;?>运行实例 »定义和用法sprintf() 函数把格式化的字符串写入一个变量中。arg1、...

weixin_42503762的博客 259

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

格式说明符

格式说明符 1.格式说明符 %d 十进制有符号整数 %i 有符号十进制整数 (与%d相同) %08d 添加前导零,确保显示的值至少包含8位 00012345(共8位) %4d 以4 位宽度显示一个整数,如 2_ _ _ 4_ _ _ 6_ _ _ 8 %f...

Sunflower的博客 6943

shell 实现N位自动补零和日期循环

用awk的printf就可以补位 # 仅适用于数字 printf "%04d\n" 86 echo 86|awk '{printf("%04d\n",$0)}' 下面是我实际应用中使用的一个脚本,目的是批量修改hdfs上的文件名,输入两个参数即可,就是开始时间和结束时间,然后用whil去循环。 #example------nohup sh hdfs_ren

京东放养的爬虫 1万+

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

shell是什么以及第一个shell脚本

1. shell是什么 (1)现在我们使用的操作系统(Windows、Mac OS、Android、iOS 等)都是带图形界面的,简单直观,容易上手,对专业用户(程序员、网管等)和普通用户(家庭主妇、老年人等)都非常适用;计算机的普及离不开图形界面。 然而在计算机的早期并没有图形界面,我们只能通过一个一个地命令来控制计算机,这些命令有成百上千之多,且不说记住这些命令非常困难,每天面对没有任何色彩的...

yrx420909的博客 440

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Alexa语音助手技术架构解析:从信号处理到技能开发的完整实现

语音交互技术作为人机交互的重要分支,其核心原理涉及信号处理、自然语言处理和机器学习等多个领域。通过麦克风阵列和波束成形技术实现噪声抑制与语音增强,利用自动语音识别将音频转化为文本,再经自然语言理解模块解析用户意图。这项技术的价值在于构建自然、高效的交互界面,广泛应用于智能家居、车载系统和客户服务等场景。本文以亚马逊Alexa为例,深入剖析其端云协同架构,涵盖从唤醒词检测到技能调度的完整流程,并分享基于用户反馈的模型迭代和边缘计算等实战经验,为开发者提供从原理到工程落地的全面指南。

weixin_30932215的博客 717

bash变量赋值及字符串的操作

转载:http://www.bsdlover.cn/html/24/n-3224.html Bash中的变量 1.用户定义的变量 用户定义的变量有字母数字及下划线组成,并且变量名的第一个字符不能为数字. 与其它UNIX名字一样,变量名是大小写敏感的. 对于变量,用户可按如下方式赋值: name = value 在引用变量时,需在前面加$符号,用户也可以在变量间进行相互赋值,如:

zhangxinrun的专栏 1万+

cisco any connect 4.4 windows

cisco any connect 4.4 windows 客户端 ''''

linux c字符串用0补位,Linux中10个你不知道的命令补齐技巧

默认情况下,bash命令行可以自动补全文件或目录名称。不过,我们可以使bash命令行补全执行更多的操作,通过补全命令可以让它成就下一个辉煌。这个教程说明了我们是怎样使用可编程的命令行补全功能(programmable completion)把自动补全的功能应用于选项或者命令行参数。例如:在输入write 命令之后,如果你按两次TAB按键,自动补全功能会提供执行write操作的列表。复制代码代码如下...

weixin_30635747的博客 1073

linux shell常用脚本命令

sed用法 打印第n行到最后一行的内容sed -n ‘1673523, $p’ bs.gi.log > /home/work/qhl/bs.gi.log 打印匹配abc的行到最后一行的内容。sed -n ‘/abc/,$p’ file.txt注意是单引号 匹配特定字符串1echo $line | sed 's/pattern...

yilan1993的专栏 172

利用正则表达式,给MAC地址补0

原输出的含MAC地址的结果为:        STRING: 0:de:fb:d8:b:d2 客户要求把MAC中只有1位的,前面要补0,变为        STRING: 00:de:fb:d8:0b:d2 还要求写成通用的方式。   Shell 正则表达式有2中方式 1. 直接补0 $ echo 'STRING: 0:d:f:d:b:d'| sed 's/\(:\|\s\)\([...

hannover100的专栏 1233
上一篇: [20181212]truncate的另类恢复5.txt
下一篇: [20181214]open file using O_DIRECT.txt
cuixun7780
博客等级 码龄10年 7粉丝 673原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值