I am trying to insert modified copies of strings after the original strings.
Here is my file:
random N:John Doe random N:Jane Roe random random N:Name Sirname random
Here you need my file to look like this:
random N:John Doe FN:John Doe random N:Jane Roe FN:Jane Roe random random N:Name Sirname FN:Name Sirname random
Any ideas for this? Cannot seem to find the correct sed / awk combination ...
sed -n ' p; s/^N:/FN:/p' original.txt
This gives:
. sed -n, , . . , p, . , s/^N:/FN:/p, FN: N: , ( , N:), .
sed -n
p
s/^N:/FN:/p
FN:
N:
:
sed -e 's/^\(N:.*\)$/\1\nF\1/g' yourfile.txt
, "N:". , \1\nF\1 ( , , "F", ).
\1\nF\1
, "" "N:".
Ampersand inserts a copy of the full match on the left side into the right side of the sed expression. Thus, using a simple wildcard to place a new line and leading F between copies of your match is all that is needed. For example:
$ sed 's/^N:.*/&\nF&/' /tmp/corpus.txt random N:John Doe FN:John Doe random N:Jane Roe FN:Jane Roe random random N:Name Sirname FN:Name Sirname random
Here is the solution awk:
awk
awk '/N:/{print $0"\nF"$0;next}1' file
$ cat file random N:John Doe random N:Jane Roe random random N:Name Sirname random
$ awk '/N:/{print $0"\nF"$0;next}1' file random N:John Doe FN:John Doe random N:Jane Roe FN:Jane Roe random random N:Name Sirname FN:Name Sirname random
Source: https://habr.com/ru/post/1524800/More articles:Использование ServiceStack Funq IoC: как впрыскиваются зависимости? - c#Intuition about a kernel trick in machine learning - statisticswarning c4307 integral constant overflow in C - c ++Redirecting to the constructor in place - c ++The DSA signature verification in C does not match the signature verification on the console. OpenSSL (enabled) - cUsing prepared data to classify a Sci-kit - pythonASP.NET using MS and Grunt packages with CDN - asp.netAndroid application class is not destroyed when last activity is destroyed - androidGetting only visible text from a QTextEdit widget - c ++gradle assembleRelease uses wrong key / certificate - androidAll Articles