sed

sum value of a 3rd row and divide rows accordingly

☆樱花仙子☆ 提交于 2020-06-27 16:22:28
问题 I have a file as below with n number of rows, I want to total it's sum(based on 3rd column) and distribute rows accordingly in 3 different files(based on sum of each) For example- if we sum all the 3rd column values it's total is coming as 516 and if we divide it by 3 it is 172. So i want to add a rows to a file so it doesn't exceed 172 mark, same with the 2nd file and rest all rows should move to the third file. Input file a aa 10 b ab 15 c ac 17 a dy 30 y ae 12 a dl 34 a fk 45 l ah 56 o aj

Sed inside jenkins pipeline

不问归期 提交于 2020-06-25 18:10:08
问题 I am trying to run the below in jenkins and i get error any suggestions? sh ''' sed -i \':a;N;$!ba;s/\\n/\\|\\#\\|/g\' ${concl} ''' Error - Why isnt the ${concl} being repalced with filename inside the shell script? + sed -i ':a;N;$!ba;s/\n/\|\#\|/g' sed: no input files 回答1: I would suggest running bash command in double quotes and escape $ and \ character. Consider following Jenkins pipeline exemplary script: #!/usr/bin/env groovy pipeline { agent any stages { stage('Build') { steps { echo

Sed inside jenkins pipeline

一个人想着一个人 提交于 2020-06-25 18:09:41
问题 I am trying to run the below in jenkins and i get error any suggestions? sh ''' sed -i \':a;N;$!ba;s/\\n/\\|\\#\\|/g\' ${concl} ''' Error - Why isnt the ${concl} being repalced with filename inside the shell script? + sed -i ':a;N;$!ba;s/\n/\|\#\|/g' sed: no input files 回答1: I would suggest running bash command in double quotes and escape $ and \ character. Consider following Jenkins pipeline exemplary script: #!/usr/bin/env groovy pipeline { agent any stages { stage('Build') { steps { echo

Format input text file strictly using sed

六眼飞鱼酱① 提交于 2020-06-17 15:45:26
问题 I have this text file named file.txt with the content bellow: Name,Height,Width,Area,Colour Rec1,5,10,50,Black Rec2,8,11,88,Red Rec3,9,13,117,Red Rec4,13,16,208,Blue Rec5,15,17,262,Red Rec6,17,19,341,Green Rec7,20,21,430,Black Rec8,22,23,528,Red Rec9,25,25,637,Blue Rec10,27,27,756,Green Rec11,30,29,885,Black Rec12,32,31,1023,Blue Rec13,35,33,1172,Red Rec14,37,35,1331,Blue Rec15,40,37,1500,Black Rec16,42,39,1678,Green Rec17,45,41,1867,Red Rec18,47,43,2066,Blue Rec19,50,45,2275,Black Rec20,52

zsh sed expanding a variable with special characters and keeping them

蓝咒 提交于 2020-06-16 17:24:09
问题 I'm trying to store a string in a variable, then expand that variable in a sed command. Several of the values I'm going to put in the variable before calling the command will have parentheses (with and without slashes before the left parentheses, but never before the right), new lines and other special characters. Also, the string will have double quotes around it in the file that's being searched, and I'd like to use those to limit only to the string I'm querying. The command needs to be

Sed: Why does [^\]] not seem to work?

泪湿孤枕 提交于 2020-06-15 18:46:47
问题 I was trying to match/output all the text before the first ] appeared: sed -i -r 's/^([^\]]*).*/\1/' "$FILE.tmp" Which surprisingly does not work. However, searching for the other bracket does work: sed -i -r 's/^([^\[]*).*/\1/' "$FILE.tmp" Is this a sed bug or am I doing it wrong? I know I can work around this using .*? which is good enough but this issue had me stumped for long enough that I'd like to know if there is something I missed. (According --version, I am using GNU sed 4.2.2.) 回答1:

How to swap the first line with last line in a text file using SED/AWK

点点圈 提交于 2020-06-15 05:50:44
问题 I am trying to swap the first line with last line in a text file in unix file has: line1 line2 line3 line4 line5 line6 I want like this: line6 line2 line3 line4 line5 line1 I am using sed -n -e '1 s/^.*$/$p' file . Which is not happening. 回答1: EDIT2: As per Ed sir's comment adding this solution too here which will be more suitable in case 2nd line is empty then also it will work. awk 'NR==1{first=$0;next} NR>2{val=val prev ORS} {prev=$0} END{print prev ORS val first} Input_file EDIT: To

Extract all ip addresses with sed and awk from a string

痴心易碎 提交于 2020-06-13 08:32:06
问题 It is simple to extract all ip addresses with grep from a string. string="221.11.165.237xxxx221.11.165.233\n 219.158.9.97ttttt219.158.19.137" echo $string |grep -oP "(\d+\.){3}\d+" 221.11.165.237 221.11.165.233 219.158.9.97 219.158.19.137 The regrex pattern is simple (\d+\.){3}\d+ . Do the same job with sed and awk. For sed: echo $string | sed 's/^\(\(\d\+\.\)\{3\}\d\+\)$/\1/g' 221.11.165.237xxxx221.11.165.233\n 219.158.9.97ttttt219.158.19.137 For awk: echo $string |gawk 'match($0,/(\d+\.){3}

Replacing caret characters with sed

烈酒焚心 提交于 2020-06-12 15:28:08
问题 I have lines in a file that look like this: FA General,1234567^^^^^FA Student Letter- General^<<undefined>>^\\path\to\file.RTF I'm trying to use sed to replace the caret characters with commas. If I use: sed 's/\^/,/' file.txt Nothing changes. I've also tried sed 's/\\^/,/' file.txt sed 's/^^/,/' file.txt What am I missing here? 回答1: Do you want to replace all carets? I am sure if you look closely at your result you'll see that the first caret is replaced. So try this: sed -e 's/\^/,/g' file

Search a pattern in file and replace another pattern in the same line

谁都会走 提交于 2020-06-08 17:23:08
问题 I would like to search for a pattern in bunch of source files. The pattern should act as a marker. If the pattern is found, I would like to process that line by performing a substitution of another string For example: Private const String myTestString = @"VAL15"; // STRING—REPLACE-VAL## Here, I want to search my source file for pattern STRING—REPLACE-VAL and then replace VAL15 with VAL20 in same. Output: private const String myTestString = @"VAL20"; // STRING—REPLACE-VAL## Tried below command