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
ETSF_IO(1)							   User Commands							ETSF_IO(1)

NAME
etsf_io - manual page for etsf_io SYNOPSIS
etsf_io [-h | -a action] [[-i file]...] [[-f flag]...] DESCRIPTION
[-o file] [arguments] Handle ETSF files, see --action option. -h --help : show this little help. -a --action value : give the action to perform. Possible action may be: * 'merge' to gather several files that have been splitted. * 'content' to get the name of specifications the file matches. * 'check' to check the validity of the file against specifications. -o --output-file file : give the path to the output ETSF file. -i --input-file file : give the path for an input file. This option can be used one or several times. -l --list : when action is check, it give the list of available flags.q -f --flag value : give a flag name (get valid names from -l option). Examples: Merge three files, etsf_io -a merge -i file1.nc -i file2.nc -i file3.nc -o output.nc Get the contents of file test.nc, etsf_io -a content test.nc Get the list of flags for validity checks, etsf_io -a check -l Checks with two flags, etsf_io -a check -f flag1 -f flag2 test.nc SEE ALSO
The full documentation for etsf_io is maintained as a Texinfo manual. If the info and etsf_io programs are properly installed at your site, the command info etsf_io should give you access to the complete manual. etsf_io November 2011 ETSF_IO(1)
All times are GMT -4. The time now is 12:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy