Visit Our UNIX and Linux User Community


copy/paste with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copy/paste with awk
# 1  
Old 09-17-2009
copy/paste with awk

Hi everybody,

I have two XML files.
I am working on a script that could copy and paste the contents of the first xml file to the desired location in the second xml file.

Here is my first XML file.
Quote:
<Signal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="XML Schema" xsi:type="ModulatedSignal">
<Name>P+</Name>
<UID>9a4MvZXb2UWM99drxGUxAg==</UID>
<ModulationFreq>55555</ModulationFreq>
<Lengths>
<double>0.21425</double>
<double>0.43574999999999997</double>
<double>0.32475</double>
<double>0.31925</double>
<double>0.22075</double>
<double>0.10625</double>
<double>0.545</double>
<double>0.64825</double>
<double>0.20975</double>
</Lengths> <SigData>AAEAAgMEBQYABAAEAAQDAgUHBX8AAQgCAwQFBggECAIFBAMCBQcFfw==</SigData>
<NoRepeats>2</NoRepeats>
<IntraSigPause>92.769</IntraSigPause>
<ToggleData/>
</Signal>
This is the second XML file.
Quote:
<?xml version="1.0" encoding="utf-8"?><SchedulerState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="XML Schema">
<Actions/>
<Macros>
<Macro>
<Pause>250</Pause>
<Position>0</Position>
<Name>New Macro</Name>
<MacroActions>
<MacroAction xsi:type="SignalAction">
<Pause>250</Pause>
<Position>0</Position>
<IROutputLocation xsi:type="RedRat3LocationInfo">
<Description>tested RedRat</Description>
<Name>changement_location</Name>
<SerialNo>2329</SerialNo>
</IROutputLocation>
<DeviceName>Premiere</DeviceName>

The contents of the first file have to appear here.

</MacroAction>
</MacroActions>
</Macro>
</Macros>
</SchedulerState>
Finaly, I wnat to obtain something like that :
Quote:
<?xml version="1.0" encoding="utf-8"?><SchedulerState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Actions/>
<Macros>
<Macro>
<Pause>250</Pause>
<Position>0</Position>
<Name>New Macro</Name>
<MacroActions>
<MacroAction xsi:type="SignalAction">
<Pause>250</Pause>
<Position>0</Position>
<IROutputLocation xsi:type="RedRat3LocationInfo">
<Description>tested RedRat</Description>
<Name>changement_location</Name>
<SerialNo>2329</SerialNo>
</IROutputLocation>
<DeviceName>Premiere</DeviceName>

<Signal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="ModulatedSignal">
<Name>P+</Name>
<UID>9a4MvZXb2UWM99drxGUxAg==</UID>
<ModulationFreq>55555</ModulationFreq>
<Lengths>
<double>0.21425</double>
<double>0.43574999999999997</double>
<double>0.32475</double>
<double>0.31925</double>
<double>0.22075</double>
<double>0.10625</double>
<double>0.545</double>
<double>0.64825</double>
<double>0.20975</double>
</Lengths> <SigData>AAEAAgMEBQYABAAEAAQDAgUHBX8AAQgCAwQFBggECAIFBAMCBQcFfw==</SigData>
<NoRepeats>2</NoRepeats>
<IntraSigPause>92.769</IntraSigPause>
<ToggleData/>
</Signal>


</MacroAction>
</MacroActions>
</Macro>
</Macros>
</SchedulerState>
I think it is possible with awk but another solution will do it too.

Thanks, Ludo
# 2  
Old 09-18-2009
Code:
sed '/<\/DeviceName>/r first.xml' second.xml


Last edited by Franklin52; 09-18-2009 at 08:22 AM.. Reason: Please use code tags!
# 3  
Old 09-18-2009
solved !

Thank you very much, it solved my problem !

Previous Thread | Next Thread
Test Your Knowledge in Computers #80
Difficulty: Easy
Many operating systems today, including Android, Chrome OS, Steam OS, and myriad embedded systems for devices, are based on Linux.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sed/awk to do like copy and paste

I have rrd file which is have the gaps and I want to fill it out with some value , I've got 10 NaN record and I try to populate data from 10 records be for NaN to change instead of NaN :( <!-- 2016-05-19 14:10:00 CST / 1463638200 -->... (11 Replies)
Discussion started by: boobytrap
11 Replies

2. Shell Programming and Scripting

Copy n paste n times

I have one mainframe copy book where I want to copy n times depend on occurs which mention below. Example: Below highlighted row mention “occurs 2 times” so I need to copy 2 times till next label 10. C14992 10 FILLER PIC X(2835). 01 ... (7 Replies)
Discussion started by: srivalli
7 Replies

3. Shell Programming and Scripting

Copy and Paste to a new document

Hello, I am quite new to shell scripting so don't know all the tools available. What I'm trying to do is open a file optimal.txt search for objectiveValue and copy the number in quotes next to it. e.g. ... solutionName="incumbent" solutionIndex="-1" objectiveValue="13246" ... (6 Replies)
Discussion started by: StephanR
6 Replies

4. UNIX for Dummies Questions & Answers

Copy/Paste in Vi editor

Dear All, I have a file containing 12 lines. First 3 lines have 9 values and the remaining 9 lines with no values. I was trying to copy and paste these 9 values of the first 3 lines into last 9 lines simultaneously as A=1.491331, B=1.539000 ..... but I don't know how to cope with this... (9 Replies)
Discussion started by: sullah
9 Replies

5. UNIX for Dummies Questions & Answers

vi copy/paste problem

I'm having a problem copy/pasting from a txt file in windows to vi. What happens is I copy a chunk of text, go to the putty terminal, go into insert mode, and right click, and it will stop pasting at a random point and freeze up. Nothing I do gets out of it. This only happens on my account... (1 Reply)
Discussion started by: solidarity
1 Replies

6. Shell Programming and Scripting

sed copy paste

Hello, I have this path and file: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt I want to end up with: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txtTHIS_SPOT Take the dir after the 10th slash, add a tab at the end and paste the dir it copied. Thanks (4 Replies)
Discussion started by: crowman
4 Replies

7. Shell Programming and Scripting

awk/grep copy and paste and insert in between lines.

Hi all, I'm a unix newb andI'm trying to write a script that can copy some text paste it in a certian place and then add a number. It's not really clear but I'll show an example. what the file looks like right now: Linux 2.6.24-24-generic (abc) 07/15/09 23:25:01 CPU ... (6 Replies)
Discussion started by: the1hand3r
6 Replies

8. Shell Programming and Scripting

Search, copy and paste

Can i search in a file for more than one string at a time? And copy the next string after that and paste it in column style? Is it possible? Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

9. UNIX for Dummies Questions & Answers

cut, copy + paste

Hi all! How do I cut, copy and paste under unix??? (2 Replies)
Discussion started by: aitor314
2 Replies

10. UNIX Desktop Questions & Answers

Cut, Copy and Paste with X

One of the things that I have learned to take for granted in the Win32 world is the cut, copy and paste hotkeys of ^X, ^C and ^V. I use these keys all the time under Win32 to copy and paste information from one GUI into another GUI. My question is, does X have a similiar standard? ... (4 Replies)
Discussion started by: auswipe
4 Replies

Featured Tech Videos