[Solved] Replacing string with variable with Groovy and SED command

In Groovy variable/expression substitution inside of strings (interpolation) only works with certain types of string literal syntax. Single quote syntax (‘content’) is not one of them. However, if you replace the outer single quotes with double quotes (“content”) then you should get the interpolation effect you are looking for: def sDescription = “foo” def sedCommand … Read more

[Solved] how to replace first line of a file using python or other tools?

Using Python 3: import argparse from sys import exit from os.path import getsize # collect command line arguments parser = argparse.ArgumentParser() parser.add_argument(‘-p’, ‘–parameter’, required=True, type=str) parser.add_argument(‘-f’, ‘–file’, required=True, type=str) args = parser.parse_args() # check if file is empty if getsize(args.file) == 0: print(‘Error: %s is empty’ % args.file) exit(1) # collect all lines first lines … Read more

[Solved] Problem replacing numbers with words from a file

this can be accomplished in a single awk call. associate numbers with champions in an array and use it for replacing numbers in second file. awk ‘BEGIN{FS=OFS=”,”} NR==FNR{a[$1]=$2;next} {$1=a[$1];$2=a[$2]} 1’ champions.csv top.csv Olaf,Annie,3 Galio,Annie,5 Twisted Fate,Annie,6 Xin Zhao,Annie,1 Urgot,Annie,10 LeBlanc,Annie,9 Vladimir,Annie,11 Kayle,Twisted Fate,12 LeBlanc,Xin Zhao,2 Galio,Galio,6 in case there should be some numbers in top.csv … Read more

[Solved] grep values and re-arranging the file

Try this awk: awk -F'”‘ ‘NR%2{p1=$4;next} {print p1 “https://stackoverflow.com/” $4}’ Test: $ awk -F'”‘ ‘NR%2{p1=$4;next} {print p1 “https://stackoverflow.com/” $4}’ file abc/123abc bac/bac123 cde/cd123 b4u/b4u234 2 solved grep values and re-arranging the file

[Solved] bash : run sed -i multiple times

Running sed -i on the same file multiple times is a horrible antipattern. Just do all the substitutions in the same sed script. You need to escape many more metacharacters than you currently do. See Escape a string for a sed replace pattern for some details. Probably that’s the reason many of your substitutions don’t … Read more

[Solved] Extract data from txt file and create new file based on specific text dynamically

Here is an easy-to-read solution with Bash and grep: #!/bin/bash while read line ; do if FILE=$(grep -P -o ‘[a-z]*\.txt(?= – Starting)’ <<< “$line”); then F=”$FILE” fi if ! grep ‘\*\*\*\*’ <<< “$line” ; then echo “$line” >> “$F” fi done It gives the following result $ cat file.txt ****************** abc.txt – Starting point ******************** … Read more

[Solved] sed parsing xml file1 index file2

the awk line should work for u: awk ‘FNR==NR{if(NR%2)i=$0;else a[i]=$0;next;}{if($0 in a){print; print a[$0]}else print}’ file2 file1 EDIT here I see no EXTRA lines. see the test. (maybe your example data format is not same as your real data.). however I have shown the way, how to do it. you can change the awk oneliner … Read more