Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Insert content from file 1 to file 2 in specific criteria meet Post 303024062 by kttan on Thursday 27th of September 2018 11:01:39 PM
Old 09-28-2018
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:
Code:
   test "sp-j1" 
   test "sp-j2" 
   test "sp-j3" 
   test "sp-j4"


file2:
Code:
sub Pre_Shorts1 (Status_Code, Message$)
global Status

   !if Message$ <> "" then  print tab(5);Message$
   !Status = Status_Code
subend

sub Pre_Shorts2 (Status_Code, Message$)
global Status

   !if Message$ <> "" then  print tab(5);Message$
   !Status = Status_Code
subend

output expected:
Code:
sub Pre_Shorts1 (Status_Code, Message$)
global Status

   if Message$ <> "" then  print tab(5);Message$
   Status = Status_Code

   test "sp-j1" 
   test "sp-j2" 
   test "sp-j3" 
   test "sp-j4" 

   call Update_Status (Status_Code, All_Failed)
subend

sub Pre_Shorts2 (Status_Code, Message$)
global Status

   !if Message$ <> "" then  print tab(5);Message$
   !Status = Status_Code
subend

currently using code is.
Code:
var=$(grep -n "sub Pre_Shorts1" testplan_temp| cut -d : -f 1) 
line=$((var+4))
#echo $line
sed -e "${line}r file1" file2 >outputfile

it still working, if the line number always same.
some of my file might have some difference, if i have file like, and i'm need insert after call Panel_Enable_Boards
Code:
sub Pre_Shorts1 (Status_Code, Message$)
global All_Failed
global BoardSet_boards_1_to_4(*)

!   if Message$ <> "" then  print tab(5);Message$
!   call Panel_Enable_Boards
!   call Update_Status (Status_Code, All_Failed)
subend

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract content from a file and insert to another file

please help for the following task... I have to extract the mac address & IP address from the file1: ... 0100004512EEF4 03 192.168.0.7 192.168.0.1 -1 ... 0100779hF5D212 03 192.168.0.8 192.168.0.1 -1 ... 0100789lF5D212 03 192.168.0.9 192.168.0.1 -1 ... ... change the format (addidng... (15 Replies)
Discussion started by: fredao
15 Replies

2. 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

3. Shell Programming and Scripting

Extract error records based on specific criteria from Unix file

Hi, I look for a awk one liner for below issue. input file ABC 1234 abc 12345 ABC 4567 678 XYZ xyz ght 678 ABC 787 yyuu ABC 789 7890 777 zxr hyip hyu mno uii 678 776 ABC ty7 888 All lines should be started with ABC as first field. If a record has another value for 1st... (7 Replies)
Discussion started by: ratheesh2011
7 Replies

4. 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

5. 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

6. Shell Programming and Scripting

awk to print specific line in file based on criteria

In the file below I am trying to extract a specific instance of path, if the adjacent plugin": "/rundb/api/v1/plugin/49/. Thank you :). file "path": "/results/analysis/output/Home/Auto_user_S5-00580-4-Medexome_65_028/plugin_out/FileExporter_out.52", "plugin": "/rundb/api/v1/plugin/49/",... (8 Replies)
Discussion started by: cmccabe
8 Replies

7. Shell Programming and Scripting

Insert content of file before the first occurrence of a line starts with a pattern in another file

Hi all, I'm new to scripting.. facing some problems while inserting content of a file into another file... I want to insert content of a file (file2) into file1, before first occurrence of "line starts with pattern" in file1 file1 ====== working on linux its unix world working on... (14 Replies)
Discussion started by: Jagadeesh Kumar
14 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. Shell Programming and Scripting

Only print specific xml values that meet two criteria in python

I have a large XML file that I want to parse, and only print one specific value if two values are met. This is the code so far: #!/usr/local/bin/python import xml.etree.ElementTree as ET tree = ET.parse('onedb-dhcp.xml') root = tree.getroot() # This successfully gets all... (1 Reply)
Discussion started by: brianjb
1 Replies
Log::Message::Item(3pm) 				 Perl Programmers Reference Guide				   Log::Message::Item(3pm)

NAME
Log::Message::Item - Message objects for Log::Message SYNOPSIS
# Implicitly used by Log::Message to create Log::Message::Item objects print "this is the message's id: ", $item->id; print "this is the message stored: ", $item->message; print "this is when it happened: ", $item->when; print "the message was tagged: ", $item->tag; print "this was the severity level: ", $item->level; $item->remove; # delete the item from the stack it was on # Besides these methods, you can also call the handlers on # the object specifically. # See the Log::Message::Handlers manpage for documentation on what # handlers are available by default and how to add your own DESCRIPTION
Log::Message::Item is a class that generates generic Log items. These items are stored on a Log::Message stack, so see the Log::Message manpage about details how to retrieve them. You should probably not create new items by yourself, but use the storing mechanism provided by Log::Message. However, the accessors and handlers are of interest if you want to do fine tuning of how your messages are handled. The accessors and methods are described below, the handlers are documented in the Log::Message::Handlers manpage. Methods and Accessors remove Calling remove will remove the object from the stack it was on, so it will not show up any more in subsequent fetches of messages. You can still call accessors and handlers on it however, to handle it as you will. id Returns the internal ID of the item. This may be useful for comparing since the ID is incremented each time a new item is created. Therefore, an item with ID 4 must have been logged before an item with ID 9. when Returns the timestamp of when the message was logged message The actual message that was stored level The severity type of this message, as well as the name of the handler that was called upon storing it. tag Returns the identification tag that was put on the message. shortmess Returns the equivalent of a "Carp::shortmess" for this item. See the "Carp" manpage for details. longmess Returns the equivalent of a "Carp::longmess" for this item, which is essentially a stack trace. See the "Carp" manpage for details. parent Returns a reference to the Log::Message object that stored this item. This is useful if you want to have access to the full stack in a handler. SEE ALSO
Log::Message, Log::Message::Handlers, Log::Message::Config AUTHOR
This module by Jos Boumans <kane@cpan.org>. Acknowledgements Thanks to Ann Barcomb for her suggestions. COPYRIGHT
This module is copyright (c) 2002 Jos Boumans <kane@cpan.org>. All rights reserved. This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-10-11 Log::Message::Item(3pm)
All times are GMT -4. The time now is 11:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy