Match the string and copy records to another location


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Match the string and copy records to another location
# 1  
Old 01-16-2009
Match the string and copy records to another location

Hi,

I have particular set of files which have the below contents:

****** PBX TYPE:ID6 PBX-id: A11 rolled on 123456 368763 00 >>>>>>
A11,2008-07-01 21:31:00.000,42,42112, ,XXXXXXXX
A11,2008-07-01 21:40:00.000,6, , ,XXXXXXX
A12,2008-07-01 21:53:00.000,68, , ,XXXXXXXX
A13,2008-07-01 21:55:00.000,8,XXXX, ,XXXXX
A11,2008-07-01 21:55:00.000,26, , ,XXXXX
A11,2008-07-01 21:55:00.000,26,XXXXX
****** PBX TYPE:GG3 PBX-id: A44 rolled on 011409 163401 00 >>>>>>
0237953 1234567890 T000018
0237953 1234567899 T000011
0236545 1234567870 T000023


I would want to copy the records starting with header as ****** PBX TYPE:ID6 to another location.

like :

****** PBX TYPE:ID6 PBX-id: A11 rolled on 123456 368763 00 >>>>>>
A11,2008-07-01 21:31:00.000,42,42112, ,XXXXXXXX
A11,2008-07-01 21:40:00.000,6, , ,XXXXXXX
A12,2008-07-01 21:53:00.000,68, , ,XXXXXXXX
A13,2008-07-01 21:55:00.000,8,XXXX, ,XXXXX
A11,2008-07-01 21:55:00.000,26, , ,XXXXX
A11,2008-07-01 21:55:00.000,26,XXXXX


How can i do that.

Thanks,
Sandeep
# 2  
Old 01-16-2009
Use nawk or /usr/xpg4/bin/awk on Solaris:

Code:
awk > output '
END { if (r ~ v) print r }
/^\*\*\*/ { 
  if (r ~ v) print r 
  f = 1; r = "" 
  }
f { r = r ? r RS $0 : $0 }
' v='\\** PBX TYPE:ID6' input

# 3  
Old 01-16-2009
Thanks. I did not get any output in the output file after running it
# 4  
Old 01-16-2009
Attached is my file, so that it would be easy for you

thanks again

Last edited by bsandeep_80; 01-16-2009 at 07:38 AM.. Reason: forgot attachment
# 5  
Old 01-16-2009
forgot attachment
# 6  
Old 01-16-2009
Could you post a bigger sample that includes the paragraphs you're interested in? I cannot find the pattern PBX TYPE:ID6 in you attachment.
# 7  
Old 01-16-2009
Attached is the file with PBX TYPE:ID6 (note there is one more PBX TYPE:CC3 ) , the output should not include these records.

I would want to copy anything that comes under this PBX TYPE:ID6( including the header,and once copied these records should get deleted

Thanks so much

Sandeep
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Shell Programming and Scripting

How to copy files from one location to another using xargs??

Hello Experts, I need to copy files from one location to another using xargs. Tried something like this (In Ubuntu & Solaris ). mkdir -p 1234; find /home/emd/Desktop/n007/M007/ -type f -name "A2014*" | xargs -0 cp -r {} /home/emd/Desktop/1234 But every time i run this, a weird error... (6 Replies)
Discussion started by: Saidul
6 Replies

3. Shell Programming and Scripting

Copy files from one location to another

I have below files in one location /test/files and also for each dates there are similar files A20130924.0000-0005_file1 A20130924.0000-0005_file2 A20130924.0005-0010_file1 A20130924.0005-0010_file2 . . . A20130924.2355-0000_file1 A20130924.2355-0000_file2 If i execute the script like... (4 Replies)
Discussion started by: Saidul
4 Replies

4. Shell Programming and Scripting

How to copy files from one location to another based on a priority?

Hi Gurus, I am a newbie to shell scripting and I am facing a problem right now.I have to automate the copy of files based on a priority.The scenario is as below: 1) There will be files from Mon-Fri with Mon file being named as abc_def_01_YYYYMMDD and Tue file being abc_def_02_YYYYMMDD and so... (4 Replies)
Discussion started by: vikramgk9
4 Replies

5. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

6. Shell Programming and Scripting

How to copy a file from one location to another location?

I have file file1.txt in location 'loc1'. Now i want a copy of this file in location 'loc2' with a new file called test.txt. Please help me how to do this in shell script. (1 Reply)
Discussion started by: vel4ever
1 Replies

7. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

8. Shell Programming and Scripting

Put one string from one location to another location in a file

Hi Everyone, I have 1.txt here a b c' funny"yes"; d e The finally output is: here a b c d e' funny"yes"; (1 Reply)
Discussion started by: jimmy_y
1 Replies

9. UNIX for Dummies Questions & Answers

Copy directory from one location to other

Hi All, I am newbie for Unix. I want to copy a directory from one location to other. Can any one help me by providing the command to do following task. thanks in advance, Rakesh (2 Replies)
Discussion started by: rakeshvthu
2 Replies

10. UNIX for Advanced & Expert Users

copy files from one location to similar location

I need help in forming a script to copy files from one location which has a sub directory structure to another location with similar sub directory structure, say location 1, /home/rick/tmp_files/1-12/00-25/ here 1-12 are the number of sub directories under tmp_files and 00-25 are sub... (1 Reply)
Discussion started by: pharos467
1 Replies
Login or Register to Ask a Question