The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
moving apache part 2 marinob007 UNIX for Dummies Questions & Answers 12 12-21-2007 03:11 PM
sh: Inserting tabs and moving text to 1 line 00000008 Shell Programming and Scripting 6 07-26-2007 05:58 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 06:39 AM
moving a file? Holistic UNIX for Dummies Questions & Answers 1 02-20-2003 07:47 PM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 03:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-03-2006
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
Moving part of Text in a file

Hi,

I have this text in a file where I need to move part of the text....

<Relation1 OriginatingObjectID="Holding_1" RelatedObjectID="Party_1" id="Relation_1">
<OriginatingObjectType tc="4">Holding</OriginatingObjectType>
<RelatedObjectType tc="6">Party</RelatedObjectType>
<RelationRoleCode tc="32">Insured</RelationRoleCode>
</Relation1>
<Relation2 OriginatingObjectID="Holding_2" RelatedObjectID="Party_2" id="Relation_2">
<OriginatingObjectType tc="4">Holding</OriginatingObjectType>
<RelatedObjectType tc="6">Party</RelatedObjectType>
<RelationRoleCode tc="32">Insured</RelationRoleCode>
</Relation2>

I want only the first line of each block in this text to be modified to

<Relation1 id="Relation_1" OriginatingObjectID="Holding_1" RelatedObjectID="Party_1">
similarly for second block ..
<Relation1 id="Relation_2" OriginatingObjectID="Holding_2" RelatedObjectID="Party_2">
and so on....
I tried it this way but could not get the complete solution...
grep "Relation1 " New_Text.txt | awk '{ print "<Relation " $4" "$2" "$3">"}'
but The result is ..
<Relation id="Relation_1"> OriginatingObjectID="Holding_1" RelatedObjectID="Party_1">
I do not want "id="Relation_1"> " instead I want id="Relation_1" This ">"should not appear after "Relation_1"...and how do I implement it in a text file where I have many blocks to be modified...and also have other blocks which does not need any change..?
  #2 (permalink)  
Old 02-04-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
>cat ty.awk

Code:
BEGIN {
FS=" "
}
{
if( $4 ~ /Relation_/ )
{
	print $1" "$4" "$2" "$3">"
}
else
{
	print $0">"
}
}
Code:
sed 's/>$//' file | awk -f ty.awk
  #3 (permalink)  
Old 02-06-2006
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
That works perfectly Thanks a lot......
  #4 (permalink)  
Old 02-06-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Why the sed and the awk ?

Just the sed would do as well.

Code:
sed -e 's_^\(<Relation[0-9]*\) \(.*\) \(.*\) \(.*\)>$_\1 \4 \2 \3>_g' input.txt
  #5 (permalink)  
Old 02-06-2006
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
This works with slight modification...
sed -e 's_\(<Relation[0-9]*\) \(.*\) \(.*\) \(.*\)>$_\1 \4 \2 \3>_g' input.txt

Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0