Read the apecific data from one file and write into another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read the apecific data from one file and write into another file
# 1  
Old 07-22-2010
Bug Read the apecific data from one file and write into another file

Hi, I would like to read the specific data from file and write the data in the new file.

My data input is something like this..

Code:
<EXROP:R=TJ0311T;
ROUTE DATA
R        ROUTE PARAMETERS
TJ0311T  DETY=UPDR     TTRANS=1   FNC=3      
         MA=628160955000      
         R=TJ0311D
         ST=7       SI=ISUP4    SP=2-1021   

         GENERIC PARAMETERS IN ROUTE OWNER
         MGG=ISUP51

END


R        ROUTE PARAMETERS
TJ0312T  DETY=UPDR     TTRANS=1   FNC=3      
         MA=628160955000      
         R=TJ0311D
         ST=7       SI=ISUP4    SP=2-1022   

         GENERIC PARAMETERS IN ROUTE OWNER
         MGG=ISUP52

END

Expected output should be....

Code:
TJ0311T  DETY=UPDR  SP=2-1021  MGG=ISUP51
TJ0312T  DETY=UPDR  SP=2-1022  MGG=ISUP52


Kindly help to write a script..
Thanks in advance.

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by bha148; 07-22-2010 at 07:44 AM..
# 2  
Old 07-22-2010
Try:

Code:
awk '/DETY/ { s=""; s=$1" "$2; } /SP=/ {s=s" "$3; } /MGG=/ { s=s" "$1; } /END/ { print s; }' file

This User Gave Thanks to dennis.jacob For This Post:
# 3  
Old 07-22-2010
another method as below

Code:
/usr/xpg4/bin/awk 'BEGIN {t1="";t2="";t3="";t4="";}
{ if ($1 ~ /TJ/ && $2 ~ /DETY/ ) { t1=$1; t2=$2; next; } }
{ if ($3 ~ /SP/) { t3=$3; next;  } }
{ if($1 ~ /MGG/) { t4=$1; next;  } }
{ if($1 ~ /END/) { print t1,t2,t3,t4}}
' file1

# 4  
Old 07-22-2010
Hi, Thanks a lot.. it works great...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

2. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

3. Shell Programming and Scripting

Read a file and write to new file with some condition

Hi.... I have a data file, which I want to split and write to new file...it looks like this... Column1 column2 Column 3 1 28.25 36.42 -----Read 5 28.26 36.42 10 28.23 36.43 15 28.22 36.43... (1 Reply)
Discussion started by: nex_asp
1 Replies

4. Shell Programming and Scripting

Read user input, Encrypt the data and write to file

Hi, can some one help me how to encrypt and decrypt a file. AIM: reade user input, encrypt it and save it to file. while decryption read the encrypted file decrypt it and save the output in some variable. Example: consider we have Credentials.txt file with content username: password... (5 Replies)
Discussion started by: saichand1985
5 Replies

5. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

6. Shell Programming and Scripting

Unfold the data from a input file and write to a file

I am working on a script to unfold data for each column from a specific line of data and write output in a single line. Input data looks like this. 2011-09-26 INF UM_10 UserMana Starting synchronization for security domain 14:37:31 080 gementSe . rvice I... (2 Replies)
Discussion started by: svajhala
2 Replies

7. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

8. Shell Programming and Scripting

Read Write byte range/chunk of data from specific location in file

I am new to Unix so will really appreciate if someone can guide me on this. What I want to do is: Step1: Read binary file - pick first 2 bytes, convert from hex to decimal. Read the next 3 bytes as well. 2 bytes will specify the number of bytes 'n' that I want to read and write... (1 Reply)
Discussion started by: Kbenipel
1 Replies

9. Programming

Read/Write a fairly large amount of data to a file as fast as possible

Hi, I'm trying to figure out the best solution to the following problem, and I'm not yet that much experienced like you. :-) Basically I have to read a fairly large file, composed of "messages" , in order to display all of them through an user interface (made with QT). The messages that... (3 Replies)
Discussion started by: emitrax
3 Replies

10. Shell Programming and Scripting

read and write from a file

I have tried to show the file name whose size is greater than 200 byte in current directory. Please help me. ls -l | tr -s " " " " | cut -f 5,9 -d " " >out.txt #set -a x `cat out.txt` i=0 `cat out.txt` | while do read x echo $x #re=200 j=0 if }" < "200" ] then echo $j j=`expr $j... (2 Replies)
Discussion started by: rinku
2 Replies
Login or Register to Ask a Question