How to cut data from file and create another file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to cut data from file and create another file.
# 1  
Old 06-29-2011
How to cut data from file and create another file.

I have file which has more than 1000 lines. PFB file info
Line 1.
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body SOAP-ENV:encodingStyle=""><matchLookup xmlns="urn:lookupGolf"><EMF1><SIGNONMSGSRQV1><SONREQ><DTCLIENT>2011-06-28 23:21:10</DTCLIENT><USERID>264757373</USERID><USERPASS>274970</USERPASS><LANGUAGE>EN</LANGUAGE><APPID>MARLOW</APPID><APPVER>268436097</APPVER></SONREQ></SIGNONMSGSRQV1><EMF1MSGSRQV1><LOOKUPTRNRQ><TRNUID>P2647573736F6280312G1LT</TRNUID><LOOKUPRQ><CUST_SUBR_NBR>002</CUST_SUBR_NBR><SBMT_OFC_NBR>002</SBMT_OFC_NBR><CTRY_CD>276</CTRY_CD><NME>TT-EDV-Beratung</NME><ADR_LINE>Schwarzwaldstr. 15</ADR_LINE><POST_TOWN>WALDBRONN</POST_TOWN><PRIM_GEO_AREA>BA</PRIM_GEO_AREA><POST_CODE>76337</POST_CODE><RTN_MAX>1000</RTN_MAX><NME_MTCH_CFDC_CD>1</NME_MTCH_CFDC_CD></LOOKUPRQ></LOOKUPTRNRQ></EMF1MSGSRQV1></EMF1></matchLookup></SOAP-ENV:Body></SOAP-ENV:Envelope>****************** | Lookup Time=2818 ms ********************
Line 2.
Same as line 1 but different info but tag are same.

I want to create another file which contain only “<DTCLIENT>2011-06-28 23:21:10</DTCLIENT>” and “<APPID>MARLOW</APPID>” tag. Please help me how can I create file.
# 2  
Old 06-29-2011
Code:
perl -lpe 's!.*(<DTCLIENT>.*?</DTCLIENT>).*(<APPID>.*?</APPID>).*!$1\n$2!' INPUTFILE

This User Gave Thanks to yazu For This Post:
# 3  
Old 06-29-2011
Code:
sed 's#.*\(<DTCLIENT>.*</DTCLIENT>\).*#\1#' input_file > dt.txt
sed 's#.*\(<APPID>.*</APPID>\).*#\1#' input_file > app.txt

This User Gave Thanks to Shell_Life For This Post:
# 4  
Old 06-29-2011
thanks both command is working fine Smilie

---------- Post updated at 10:26 PM ---------- Previous update was at 09:58 PM ----------

i want to add "Lookup Time=2818 ms" too in file plz help how will be i do it.

---------- Post updated at 10:39 PM ---------- Previous update was at 10:26 PM ----------

i want to add " Lookup Time= " too in " perl -lpe 's!.*(<DTCLIENT>.*?</DTCLIENT>).*(<APPID>.*?</APPID>).*!$1\n$2!' INPUTFILE " command please help

Last edited by humaemo; 06-29-2011 at 01:44 PM..
# 5  
Old 06-30-2011
Try:
Code:
perl -lpe 's!.*(<DTCLIENT>.*?</DTCLIENT>).*(<APPID>.*?</APPID>).*(Lookup Time=[^*]*).*!$1\n$2\n$3!'

# 6  
Old 06-30-2011
command is not working. instead of Lookup time deatails it is displaying full tag .
# 7  
Old 06-30-2011
The command works. Either your input is different or you are did something wrong:
Code:
$ cat >testfile
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body SOAP-ENV:encodingStyle=""><matchLookup xmlns="urn:lookupGolf"><EMF1><SIGNONMSGSRQV1><SONREQ><DTCLIENT>2011-06-28 23:21:10</DTCLIENT><USERID>264757373</USERID><USERPASS>274970</USERPASS><LANGUAGE>EN</LANGUAGE><APPID>MARLOW</APPID><APPVER>268436097</APPVER></SONREQ></SIGNONMSGSRQV1><EMF1MSGSRQV1><LOOKUPTRNRQ><TRNUID>P2647573736F6280312G1LT</TRNUID><LOOKUPRQ><CUST_SUBR_NBR>002</CUST_SUBR_NBR><SBMT_OFC_NBR>002</SBMT_OFC_NBR><CTRY_CD>276</CTRY_CD><NME>TT-EDV-Beratung</NME><ADR_LINE>Schwarzwaldstr. 15</ADR_LINE><POST_TOWN>WALDBRONN</POST_TOWN><PRIM_GEO_AREA>BA</PRIM_GEO_AREA><POST_CODE>76337</POST_CODE><RTN_MAX>1000</RTN_MAX><NME_MTCH_CFDC_CD>1</NME_MTCH_CFDC_CD></LOOKUPRQ></LOOKUPTRNRQ></EMF1MSGSRQV1></EMF1></matchLookup></SOAP-ENV:Body></SOAP-ENV:Envelope>****************** | Lookup Time=2818 ms ********************
app@kf3sv ~/tmp
$ perl -lpe 's!.*(<DTCLIENT>.*?</DTCLIENT>).*(<APPID>.*?</APPID>).*(Lookup Time=[^*]*).*!$1\n$2\n$3!' testfile
<DTCLIENT>2011-06-28 23:21:10</DTCLIENT>
<APPID>MARLOW</APPID>
Lookup Time=2818 ms

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut a script name to create a blank file

I have a requirement to read a list of script names create a .finish blank file for each of them. The script names can be like: - ScriptName.sh - ScriptName.sh Param1 - ScriptName.sh Param1 Param2 I need to create files like below using the same script: - ScriptName.finished -... (6 Replies)
Discussion started by: member2014
6 Replies

2. Shell Programming and Scripting

Need to cut a some required data from file

Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: ORA-00942: table or view does not exist I have some thing like above in the file.. Upto this portion Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: the length can be vary .. Can some one help me in taking this portion alone ORA-00942:... (7 Replies)
Discussion started by: saj
7 Replies

3. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

4. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

5. Shell Programming and Scripting

Cut and paste data in new file

HI Guys, I have file A: Abc XyZ Abc Xyz Kal Kaloo Abc XyZ Abc Xyz Kalpooo Abc XyZ Abc Xyz Kloo Abc Abc Klooo I want file B Abc XyZ Abc Xyz Kal Kaloo Abc XyZ Abc Xyz Kalpooo Abc XyZ Abc Xyz Kloo File A is now 1 lines Abc Abc Klooo Cut all lines which have xyz... (2 Replies)
Discussion started by: asavaliya
2 Replies

6. Shell Programming and Scripting

Copy data form File A and Create File B

File A I have list of : ABCND1 ABCND2 ABCnd3 ABCnd4 I want file B like below Start+ S Pate=ABCND1 AAlo1 S Pate=ABCND1 Q1234 S Pate=ABCND1,P12345 (7 Replies)
Discussion started by: asavaliya
7 Replies

7. Shell Programming and Scripting

create a new file from data file from a column

I have a data file that has a list of data macthing by user. I am able to sort by user and there is multiple rows for each user. Ideally I would like to email only the user of the files they own. Would it be best to create a seperate file by user and all rows showing the files they own? (9 Replies)
Discussion started by: mykey242
9 Replies

8. Shell Programming and Scripting

How to cut some data from big file

How to cut data from big file my file around 30 gb I tried "head -50022172 filename > newfile.txt ,and tail -5454283 newfile.txt. It's slowy. afer that I tried sed -n '46467831,50022172p' filename > newfile.txt ,also slow Please recommend me , faster command to cut some data from... (4 Replies)
Discussion started by: almanto
4 Replies

9. UNIX for Dummies Questions & Answers

create data file from report file

Dear Ones, kindly help me to create a data file from the report file as shown here under( i am new one to unix KNOW BASIC COMMANDS) file:rama.prt (ist record)(3 to 4 lines of text with different filed names) Name :M.LALITHA DOB:12/11/45 DESG :JA(P) STANO:300175 ... (3 Replies)
Discussion started by: cvvsnm
3 Replies
Login or Register to Ask a Question