logo
Tags down

shadow

Insert content from a file after specific pattern regex match by using sed in bash


By : karishmahaque
Date : October 14 2020, 02:24 PM
it should still fix some issue Perl may not be your option, but it's worth a try. With Perl you can say:
code :
perl -0777 -ne 'if ($. == 1) {$replace = $_; next} s#(?=//\*\*insert_yannyann\*//)#$replace#g; print' a.txt b.txt > b_new.txt
...

1234
5678
9101
//**insert_yannyann*//

...
awk 'NR==FNR {replace = replace $0 RS; next}
    {text = text $0 RS}
    END {
        print gensub(/\/\/\*\*insert_yannyann\*\/\//, replace "&", "g", text)
    }' a.txt b.txt > b_new.txt


Share : facebook icon twitter icon

Insert contents of a file after specific pattern match


By : ati.rh
Date : March 29 2020, 07:55 AM
hop of those help? I want to insert file content at specific pattern match. The following is an example: add file2.txt content in file1.txt between and . , Try following command:
code :
sed '/<tag>/ r file2.txt' file1.txt
<html>
<body>
<tag>
Hello world
</tag>
</body>
</html>

Insert content of file after first pattern match using sed


By : jmchappell
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You need to use double quotes( " ) to access the shell variable( $BLA ) in sed. Try this,
code :
sed "/all.css/ r $BLA" "$FILE" > TMP1

regex to match pattern of file of specific record


By : Stanislav Kocan
Date : March 29 2020, 07:55 AM
will help you I'm having files like given below I want to validate my file if first line is having "ZZ=" and third record is having only "XXX" , Try this
code :
/ZZ=\d+.+XXX.+/s

bash shell-How to swift a file specific content with another file after a match pattern found


By : NehaS
Date : March 29 2020, 07:55 AM
wish helps you , A straight forward way by awk,
code :
$ awk 'NR==FNR{a[NR]=$0;next}{sub(/\ /,a[FNR])}1' file2 file1
aa1bb
ccc2dd
ee3fff

Insert content of file at specific line number of another file in LINUX/BASH


By : user3520892
Date : March 29 2020, 07:55 AM
hop of those help? You can do it with awk fairly easily using a variable to serve as a flag to only write the contents of tempfile once after the first occurrence of "@type ABCDF". The approach is simple, you output every line with the first {print} rule, then if /@type ABCDF/ && n, you loop with getline reading each line from tempfile and outputting it. When done outputting the file, you simply set n=0 and it will skip all the other occurrences of "@type ABCDF" in the file, e.g.
code :
awk -vn=1 '{print}; /@type ABCDF/ && n{while (getline <"tempfile") print;n=0}' file1 
$ cat file1
File1
 @type ABCDF #---Insert 'tempfile' content below First occurrence '@type ABCDF'
File2
File3
 @type ABCDF
File4
 @type ABCDF
File5
$ awk -vn=1 '{print}; /@type ABCDF/ && n{while (getline <"tempfile") print;n=0}' file1
File1
 @type ABCDF #---Insert 'tempfile' content below First occurrence '@type ABCDF'
tempFile 01
tempFile 02
tempFile 03
tempFile 03
File2
File3
 @type ABCDF
File4
 @type ABCDF
File5
shadow
Privacy Policy - Terms - Contact Us © voile276.org