Skip to main content
The 2024 Developer Survey results are live! See the results
question edited after 1st comment for better understanding
Source Link
Rizwan.A
  • 43
  • 2
  • 10

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk -F / "{ print $4; }" names.txt all names are on 4th position on each line

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

I want to use sed command to search word have and add line before pattern match line

sed -i "/have/ s/^/oslo good owner="Jim" and too good\n/" list.txt

and its works, but write all line with same name.

I want to use awk outputcommand result in sed, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

I use sed command to do so but unfortunately not successful, awk command not working and I also don't know will this add lines before all pattern match lines or not

sed -i "/have/ s/^/oslo good owner="$(awk -F / "{ print $4; }" names.txt) and too good\n/" list.txt

unable to solve this, did google many times and searched stack

working in windows-10 environment command prompt

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk -F / "{ print $4; }" names.txt all names are on 4th position on each line

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

I want to use sed command to search word have and add line before pattern match line with awk output, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

I use sed command to do so but unfortunately not successful, awk command not working and I also don't know will this add lines before all pattern match lines or not

sed -i "/have/ s/^/oslo good owner="$(awk -F / "{ print $4; }" names.txt) and too good\n/" list.txt

unable to solve this, did google many times and searched stack

working in windows-10 environment command prompt

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk "{ print $4; }" names.txt all names are on 4th position on each line

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

sed command search word have and add line before pattern match line

sed -i "/have/ s/^/oslo good owner="Jim" and too good\n/" list.txt

and its works, but write all line with same name.

I want to use awk command result in sed, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

working in windows-10 environment command prompt

added 43 characters in body
Source Link
Rizwan.A
  • 43
  • 2
  • 10

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk -F / "{ print $4; }" names.txt all names are on 4th position on each line

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

I want to use sed command to search word have and add line before pattern match line with awk output, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

I use sed command to do so but unfortunately not successful, awk command not working and I also don't know will this add lines before all pattern match lines or not

sed -i "/have/ s/^/oslo good owner="$(awk -F / "{ print $4; }" names.txt) and too good\n/" list.txt

unable to solve this, did google many times and searched stack

working in windows-10 environment command prompt

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk -F / "{ print $4; }" names.txt

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

I want to use sed command to search word have and add line before pattern match line with awk output, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

I use sed command to do so but unfortunately not successful, awk command not working and I also don't know will this add lines before all pattern match lines or not

sed -i "/have/ s/^/oslo good owner="$(awk -F / "{ print $4; }" names.txt) and too good\n/" list.txt

unable to solve this, did google many times and searched stack

working in windows-10 environment command prompt

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk -F / "{ print $4; }" names.txt all names are on 4th position on each line

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

I want to use sed command to search word have and add line before pattern match line with awk output, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

I use sed command to do so but unfortunately not successful, awk command not working and I also don't know will this add lines before all pattern match lines or not

sed -i "/have/ s/^/oslo good owner="$(awk -F / "{ print $4; }" names.txt) and too good\n/" list.txt

unable to solve this, did google many times and searched stack

working in windows-10 environment command prompt

Source Link
Rizwan.A
  • 43
  • 2
  • 10

pipe awk output in sed command

I have multiple lines in a file names.txt, let's say

my name is Jim your name please
what is good Harry potter
how is he Jhony and me

and so on , more than 500 lines.

I use awk command to search/ print only names awk -F / "{ print $4; }" names.txt

following command outputs

Jim
Harry
Jhony

and so on, more than 500 names.

I use sed command to print lines before each line which matches pattern. list.txt already have many lines. let's say

hero is always good and have alpha name
jungle is also called forest and beta owner
carrots are sweet have gama solution

I want to use sed command to search word have and add line before pattern match line with awk output, e.g require output in list.txt file should be

olso good owner="Jim" and too good
hero is always good and have alpha name
jungle is also called forest and beta owner
olso good owner="Harry" and too good
carrots are sweet have gama solution

and so on, till list.txt file ends.

I use sed command to do so but unfortunately not successful, awk command not working and I also don't know will this add lines before all pattern match lines or not

sed -i "/have/ s/^/oslo good owner="$(awk -F / "{ print $4; }" names.txt) and too good\n/" list.txt

unable to solve this, did google many times and searched stack

working in windows-10 environment command prompt