sed

Extract values from specific row, column using bash

社会主义新天地 提交于 2021-01-28 15:07:04
问题 I have a sample log file with fields and values in this format value1 value2 50 100 value3 value4 10 150 value5 200 I need to extract fields and values to something of this format value1=50 value2=100 value3=10 value4=150 value5=200 回答1: Try this awk: gawk '{split($0,n_arr," "); getline; n=split($0,v_arr," "); getline; for (i=1;i<=n;i++){print n_arr[i] "=" v_arr[i]}}' 回答2: awk '/value/ { if ((getline values) > 0) { split(values, array) for (i = 1; i <= NF; i++) print $i "=" array[i] } }'

Extract values from specific row, column using bash

安稳与你 提交于 2021-01-28 15:05:28
问题 I have a sample log file with fields and values in this format value1 value2 50 100 value3 value4 10 150 value5 200 I need to extract fields and values to something of this format value1=50 value2=100 value3=10 value4=150 value5=200 回答1: Try this awk: gawk '{split($0,n_arr," "); getline; n=split($0,v_arr," "); getline; for (i=1;i<=n;i++){print n_arr[i] "=" v_arr[i]}}' 回答2: awk '/value/ { if ((getline values) > 0) { split(values, array) for (i = 1; i <= NF; i++) print $i "=" array[i] } }'

Extract values from specific row, column using bash

ε祈祈猫儿з 提交于 2021-01-28 15:01:16
问题 I have a sample log file with fields and values in this format value1 value2 50 100 value3 value4 10 150 value5 200 I need to extract fields and values to something of this format value1=50 value2=100 value3=10 value4=150 value5=200 回答1: Try this awk: gawk '{split($0,n_arr," "); getline; n=split($0,v_arr," "); getline; for (i=1;i<=n;i++){print n_arr[i] "=" v_arr[i]}}' 回答2: awk '/value/ { if ((getline values) > 0) { split(values, array) for (i = 1; i <= NF; i++) print $i "=" array[i] } }'

Appending 0's to a file in unix/bash if the line is less than a fixed length

浪子不回头ぞ 提交于 2021-01-28 13:57:39
问题 I am looking for a way in which to append 0's to the end of multiple lines in a file if they are less than 66 characters in length so that the total line length equals 66. Here's an example of the file format (... denotes preceding 56 characters): $cat file1 ...1234567891 ...123456 ... ...12345678 Ideal format: ...1234567891 ...1234560000 ...0000000000 ...1234567800 回答1: GNU awk solution: $ awk '{s=$0; while(length(s)<66) s=s "0"; print s}' file1 or even shorter: $ awk '{while(length<66) $0=

Bash: replace entire string in one column based on matching substring

怎甘沉沦 提交于 2021-01-28 12:43:50
问题 I have a large file with many columns and rows. I would like to replace an entire string in the first column based on a substring that's common to all strings I want to replace. Here's an example of what I have: AAA_1765 866 HTG AAA_1873 987 IGA AAA_1922 413 BOK I would like all strings in the first column that contain the substring AAA_1 be entirely replaced with another string, so that it looks like this: BBB_2 866 HTG BBB_2 987 IGA BBB_2 413 BOK I've been working with sed to do a search

Is it possible to use sed to replace dependencies's version in a pom file?

旧时模样 提交于 2021-01-28 12:12:42
问题 I have a pom.xml file and I want to replace the version inside any of the dependency nodes from 0.1-SNAPSHOT to a different version (let's say NEW-VERSION ), the only restriction I have is that the replacement should be done only if the groupId matches a particular text, lets say: com.company.xyz . That being said, let's say this is the dependencies section of my pom.xml : <dependencies> <dependency> <groupId>com.company.xyz</groupId> <artifactId>xyz-xx-utils</artifactId> <version>0.1

Remove duplicate line only contain specific string

只谈情不闲聊 提交于 2021-01-28 12:10:57
问题 I try to remove duplicates lines only if contain a specific string. It's easy to remove only duplicates lines, but some useful lines is deleted with : awk '!seen[$0]++' or perl -ne 'print unless $seen{$_}++' Exemple : keep first occurence of lines containing "host_name=" keep all occurrences of lines containing "plugin output=" with above awk or Perl commands that delete the client number too. My output command : host_name=Client1 plugin_output=Name : Client1 Marseille host_name=Client1

Find pattern and append in sed

元气小坏坏 提交于 2021-01-28 12:06:42
问题 I am having difficulty to find a pattern and append line before the pattern in sed Suppose i want to find the following pattern with sed "stackov/er;flo.w users are great" Note:The pattern to be search contain double quotes , /, ; and dot And then append this line just before pattern proud sta{ckov,er member My attempts 1. sed "|"stackov/er;flo.w users are great"|i\proud sta{ckov,er member" file 2. sed "/stackov/er;flo.w users are great|i\proud sta{ckov,er member" file I tried to replace the

Sed command ignoring single quotes in Groovy scripts

谁说胖子不能爱 提交于 2021-01-28 08:27:26
问题 Hello I am facing this issue when I try to replace string using SED in Groovy, it's ignoring the Single quotes which I am passing. Here is my code I tried using double quotes inside sed and it's throwing errors. stage('Version') { dir('./Dest/Scripts/') { sh "sed -i 's/VERSION_BUILD=0/VERSION_BUILD= '$Version', System2 = '$name'/g' setversion.sql" } } My desired output is UPDATE &Shared_Version SET SharedVersion = '2010', System1 = 'XXXX', InetsoftVersion = 2, VERSION_BUILD='20180302',

Bash one-liner to mask data in file

こ雲淡風輕ζ 提交于 2021-01-28 07:42:11
问题 I have a file which is quite big. I need to mask all characters in specific postions and from a specific record type. I have searched all over the place but cannot find a solution of this quite simple task. Here is an example File name: hello.txt File: 0120140206INPUT FILE 1032682842 MR SIMPSON 20231458 742 Evergreen Terrace 3034560817 GREEN 1032682842 MR GRIFFIN 20231458 Spooner Street 3034560817 RED 3001 What I would like to do is to mask position 12-16 of all lines beginnning with "10".