sed

Using sed to replace number greater than a specified number in an specified position using shell scripting

蓝咒 提交于 2020-04-16 02:48:26
问题 I need to write a script to replace all the numbers greater than an specified number which is in following position. 1499011200 310961583 142550756 313415036 146983209 Here I am writing a script if the second term exceeds in value greater than 300000000. I need the whole line to be replaced by my desired value like 1499011200 250000000 XXXX XXXX XXXX I hope I have made my question clear. Thanks in advance 回答1: This might work for you (GNU sed): sed -r '/^\S+\s+(300000000|[1-2][0-9]{8}|[0-9]{1

Using sed to replace number greater than a specified number in an specified position using shell scripting

依然范特西╮ 提交于 2020-04-16 02:48:10
问题 I need to write a script to replace all the numbers greater than an specified number which is in following position. 1499011200 310961583 142550756 313415036 146983209 Here I am writing a script if the second term exceeds in value greater than 300000000. I need the whole line to be replaced by my desired value like 1499011200 250000000 XXXX XXXX XXXX I hope I have made my question clear. Thanks in advance 回答1: This might work for you (GNU sed): sed -r '/^\S+\s+(300000000|[1-2][0-9]{8}|[0-9]{1

Mac OS X 使用命令sed替换tab

不羁岁月 提交于 2020-04-10 13:18:05
中文版 使用Mac OSX上的sed的时候,如果想替换tab这个特殊字符,会出现很多奇奇怪怪的问题。当很很多其他也一样,有时候用Mac上的命令就是蛋疼蛋疼。 这个问题有很多问法,我们暂且把它转化为如何在Mac 的terminal下面输入sed可以识别的tab的字符。 通过上面的方法你可以得到sed 可以识别的tab字符。 试试下面的命令: English version How can I insert a tab character with sed on OS X? Mac OSX's sed can't understand \t be Tab, therefore, we need to insert Tab for another way. 日本語版 MacOSX上でsedを利用して、tab文字の置換をやろうとして、つまづいたのでメモ。 とかしてみたけど、全然効かず。 いろいろやってみて効いた方法が  C-v → Ctr-v  tab → 普通にTABキー これで実行したら出来た。 MacOS上だけなのかなー。 Reference Stackoverflow-How can I insert a Tab with sed in OSX mac OSX で sedを使ってtabの文字列を置換 来源: oschina 链接: https://my.oschina.net/u

【Spring Cloud & Kubernetes教程】1. 构建生产级别Linux系统

前提是你 提交于 2020-04-08 13:50:51
macOS使用VM安装CentOS7系统 前面步骤就不截图了百度很多,选择安装系统的iso文件 启动虚拟机第一步直接确定等一会到选择语言 默认英语就行 选择完直接点Begin Installation 第一项设置root 密码,设置完点Done,等待安装 到处安装完成。 登录系统 网络配置 本机自动分配的IP,记得虚拟机网络一定要选择桥接模式 准备修改为固定IP 设置为130固定IP 保存,重启网卡 测试网关 主机名配置 YUM源更新 时钟同步 内核参数配置 语言时区 关闭SELINUX,防火墙 SSH参数配置 这里直接用脚本执行: 这个脚本只适合CentOS 7 x86_64系统使用 #!/bin/bash # init centos7 ./centos7-init.sh 主机名 # 检查是否为root用户,脚本必须在root权限下运行 if [[ "$(whoami)" != "root" ]]; then echo "please run this script as root !" >&2 exit 1 fi echo -e "\033[31m the script only Support CentOS_7 x86_64 \033[0m" echo -e "\033[31m system initialization script, Please Seriously.

median of column with awk

风流意气都作罢 提交于 2020-04-08 02:03:33
问题 How can I use AWK to compute the median of a column of numerical data? I can think of a simple algorithm but I can't seem to program it: What I have so far is: sort | awk 'END{print NR}' And this gives me the number of elements in the column. I'd like to use this to print a certain row (NR/2) . If NR/2 is not an integer, then I round up to the nearest integer and that is the median, otherwise I take the average of (NR/2)+1 and (NR/2)-1 . 回答1: This awk program assumes one column of numerically

median of column with awk

[亡魂溺海] 提交于 2020-04-08 02:00:10
问题 How can I use AWK to compute the median of a column of numerical data? I can think of a simple algorithm but I can't seem to program it: What I have so far is: sort | awk 'END{print NR}' And this gives me the number of elements in the column. I'd like to use this to print a certain row (NR/2) . If NR/2 is not an integer, then I round up to the nearest integer and that is the median, otherwise I take the average of (NR/2)+1 and (NR/2)-1 . 回答1: This awk program assumes one column of numerically

median of column with awk

◇◆丶佛笑我妖孽 提交于 2020-04-08 02:00:04
问题 How can I use AWK to compute the median of a column of numerical data? I can think of a simple algorithm but I can't seem to program it: What I have so far is: sort | awk 'END{print NR}' And this gives me the number of elements in the column. I'd like to use this to print a certain row (NR/2) . If NR/2 is not an integer, then I round up to the nearest integer and that is the median, otherwise I take the average of (NR/2)+1 and (NR/2)-1 . 回答1: This awk program assumes one column of numerically

使用sed -i对文本字符串进行增删改查

别等时光非礼了梦想. 提交于 2020-04-07 13:27:38
sed是一个很好的文件处理工具,本身是一个管道命令,主要以行为单位进行处理,可以将数据行进行替换、删除、新增、选取等特定工作。 1. sed命令行格式 sed [选项] [命令] 1 1.1 选项 -n,使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN 的数据一般都会被列出到终端上。但如果加上 -n 参数后,则只有经过sed特殊处理的那一行(或者动作)才会被列出来。 -e,直接在命令列模式上进行sed的动作编辑。 -f,直接将sed的动作写在一个文件内。-f filename 则可以运行filename内的sed命令。 -r,sed 的动作支持的是延伸型正规表示法的语法。(默认是基础正规表示法语法) -i,直接修改读取的文件内容,而不是输出到终端。 1.2 指定行数 [n1[,n2]]function n1, n2,不一定存在,一般代表“选择进行动作的行数”,如果我的动作需要在10到20行之间进行,则有’10,20命令’ 1.3 常用命令 a,新增,a的后面可以接字符串,而这些字符串会在新的一行出现(目前的下一行) c,取代,c的后面可以接字符串,这些字符串可以取代n1,n2 之间的行 d,删除,因为是删除,所以d后面通常不接任何东西 i,插入,i的后面可以接字符串,而这些字符串会在新的一行出现(目前的上一行) p,输出,即将某个选择的文件输出

sed[1]

廉价感情. 提交于 2020-04-07 02:03:27
Sed 命令列可分成编辑指令与文件档部份。其中 , 编辑指令负责控制所有的编辑工作 ; 文件档表示所处理的档案。 sed 的编辑指令均由位址(address)与函数(function)两部份组成 , 其中 , 在执行时 , sed 利用它的位址参数来 决定编辑的对象;而用它的函数参数(解[3])编辑。 此外 , sed 编辑指令 , 除了可在命令列上执行 , 也可在档案内执行。其中差别只是在命令列上执行时 , 其前必 须加上选项 -e ; 而在档案(解[4])内时 , 则只需在其档名前加上选项 -f。另外 , sed 执行编辑指令是依照它 们在命令列上或档内的次序。 下面各节 , 将介绍执行命令列上的编辑指令 、sed 编辑指令、执行档案内的编辑指令、执行多个档案的编辑、及 执行 sed 输出控制。 2.1 执行命令列上的编辑指令 2.2 sed 编辑指令 2.3 执行档案内的编辑指令 2.4 执行多个档案的编辑 2.5 执行 sed 输出控制 2.1.执行命令列上的编辑指令 当编辑指令(参照[section 2.2])在命令列上执行时 , 其前必须加上选项 -e 。其命令格式如下 : sed -e '编辑指令1' -e '编辑指令2' ... 文件档 其中 , 所有编辑指令都紧接在选项 -e 之後 , 并置於两个 " ' " 特殊字元间。另外 , 命令上编辑指令的执行是由 左而右

Linux文本处理之sed

瘦欲@ 提交于 2020-04-06 17:28:20
sed(stream editer),流编辑器,对标准输出或文件逐行进行处理 一、语法格式: 1、stdout | sed [option] "pattern command" 2、sed [option] "pattern command" file 二、sed的选项 -n 只打印模式匹配行(静默模式) 在sed的用法中,所有来自标准输入的内容都要print到屏幕,加-n后只显示经过sed处理的内容 -e 直接在命令行进行sed编辑,默认选项(只有1个时可以省略) -f 编辑动作保存在文件中,指定文件执行 -r 支持扩展正则表达式 -i 直接修改文件内容(重要) 三 、sed中的pattern详解 匹配模式 含义 10command 匹配到第10行(例:sed -n '10p' /etc/passwd,cat -n /etc/passwd)---p代表打印print 10,20command 匹配从第10行开始,到第20行结束 10,+5command 匹配从第10行开始,到第15行结束(例:sed -n '10,+5p' /etc/passwd ) /pattern1/command 匹配到pattern1的行(例:sed -n '/\/sbin\/nologin/p' /etc/passwd) /pattern1/,/pattern2/command