Skip to content
Advertisement

Copying multiple text lines into a file after specified pattern using shell [closed]

I want to insert multiple line from file1 marked with pattern into a file2 using shell.
The pattern is 10 numbers, always different input exmple: “2016854218”

file1 example (input):

JavaScript

file2 example (output):

JavaScript

Advertisement

Answer

EDIT: Since OP wants to have http link’s complete value till all the digits s adding this solution now too.

JavaScript

Could you please first if you have control M characters in your Input_file by doing cat -v Input_file if yes then run dos2unix utility in case you have it. In case you don’t have it use:

JavaScript

but above will remove all control M characters, so to remove control Ms on last of the line(in case) use:

JavaScript

Now once your control Ms are not there on Input_file then you could use following:

JavaScript

You could remove --re-interval in case you have newer version of GNU awk with you.

Advertisement