Sponsored Content
Top Forums Shell Programming and Scripting Insert content of file before the first occurrence of a line starts with a pattern in another file Post 302982692 by disedorgue on Sunday 2nd of October 2016 12:09:44 PM
Old 10-02-2016
Hi,
Another way with gnu sed:
Code:
$ cat f1.txt 
working on linux
its unix world
working on unix
its linux world
unix is best          --> first occurrence of line starts with unix
linux is easy
unix is easy
unix is best
linux is best

Code:
$ cat f2.txt 
Here is my content
i want to insert this

Code:
$ sed -e '0,/^unix/{/^unix.*/s//cat f2.txt;echo "&"/e;}' f1.txt
working on linux
its unix world
working on unix
its linux world
Here is my content
i want to insert this
unix is best          --> first occurrence of line starts with unix
linux is easy
unix is easy
unix is best
linux is best

Regards.

Last edited by disedorgue; 10-03-2016 at 05:36 AM.. Reason: to correct error noticed by scrutinizer
This User Gave Thanks to disedorgue For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert content of a file after a certain line in another file

Hi, it's my first post to this forum. I just started bash and I'm stuck at one issue. I want to include content of a file in another file after a certain line. I'm using sed for inserting one line but how to insert all content of a file ? For example i have a file list.txt with a few lines and... (4 Replies)
Discussion started by: ktm
4 Replies

2. Shell Programming and Scripting

how to delete lines from a file which starts with a specific pattern

I need to delete those lines from a file, which starts with 45. How to do it? (3 Replies)
Discussion started by: mady135
3 Replies

3. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

4. Shell Programming and Scripting

How to insert file contents after nth occurrence of a string using sed?

Hi, I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g. > cat file1 banana apple orange apple banana pear tangerine apple > cat file2 I don't like apples What would be the sed command to insert... (5 Replies)
Discussion started by: dimocn
5 Replies

5. Shell Programming and Scripting

Insert content of a file into another file before given pattern

I need to insert file x2 into x1 right before first BBB line. $ cat x1 AAA 1 AAA 2 AAA 3 BBB 1 BBB 2 BBB 3 $ cat x2 XXX - insert 1 XXX - insert 2 I need to get AAA 1 AAA 2 AAA 3 XXX - insert 1 XXX - insert 2 BBB 1 (2 Replies)
Discussion started by: migurus
2 Replies

6. Shell Programming and Scripting

awk command to get file content until 2 occurrence of pattern match

AWK command to get file content until 3 occurrence of pattern match, INPUT FILE: JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2"> <person>Romi</person> <appName>SAP</appName> </custOptIn> ... (4 Replies)
Discussion started by: prince1987
4 Replies

7. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

8. Shell Programming and Scripting

Insert content of a file right after pattern in another file

suppose i have original file: original.txt: hello how are you you are wonderful what time is it I went to the store last night. and some apple juice then i have another file: anotherfile.txt: with my friends mary, john and harry. We had a great time. We bought food Suppose... (1 Reply)
Discussion started by: SkySmart
1 Replies

9. UNIX for Beginners Questions & Answers

Insert content from file 1 to file 2 in specific criteria meet

Hi , I'm looking for some code that can copy and paste form file1 to file2 with 2 criterial meet. file1: test "sp-j1" test "sp-j2" test "sp-j3" test "sp-j4" file2: sub Pre_Shorts1 (Status_Code, Message$) global Status !if Message$ <> "" then print... (3 Replies)
Discussion started by: kttan
3 Replies
UML_SWITCH(1)                                                 General Commands Manual                                                UML_SWITCH(1)

NAME
uml_switch -- switch daemon for user-mode Linux SYNOPSIS
uml_switch [-unix control_socket data_socket] [-hub] [-tap tun device] [-compat-v0] [-daemon] DESCRIPTION
This manual page documents briefly the uml_switch program. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. uml_switch is a daemon for managing a virtual network between user-mode Linux systems, with no connection to the host system's network. It will listen for connections on a pair of UNIX domain sockets, and forward packets between clients which connect to them. OPTIONS
-unix control_socket data_socket Listen on the specified pair of sockets, instead of the defaults. -hub Act like a hub. This means that packets received will be broadcast over all virtual links. The default is to act as a switch, where packets are only sent to the link matching the destination MAC address of the packet. -tap tap device Connect the switch to a dynamically created tap device on the host -compat-v0 Specify control protocol version 0 compatibility. -daemon Run in the background as a daemon. SEE ALSO
linux(1) The UserModeLinux-HOWTO (link to URL http://user-mode-linux.sourceforge.net/UserModeLinux-HOWTO.html) AUTHOR
uml_switch was written by Jeff Dike and others. This manual page was written by Matt Zimmerman mdz@debian.org for the Debian GNU/Linux system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. UML_SWITCH(1)
All times are GMT -4. The time now is 11:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy