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
# 8  
Old 01-16-2009
I though this was the desired output,
am I missing something?

Code:
zsh-4.3.9[t]% awk '
quote> END { if (r ~ v) print r }
quote> /^\*\*\*/ { 
quote>   if (r ~ v) print r 
quote>   f = 1; r = "" 
quote>   }
quote> f { r = r ? r RS $0 : $0 }
quote> ' v='\\** PBX TYPE:ID6' test1.txt
****** PBX TYPE:ID6    PBX-id: L14      polled on 011409 133905           00 >>>>>>
L14,2009-01-14 13:36:00.000,64,38772, ,18905238433,E,38772, , ,052,046,N,00, ,2009-01-14 13:36:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486634
L13,2009-01-14 13:37:00.000,0, , ,1448845,E, ,052,016, , ,IN,00, ,2009-01-14 13:37:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486636
L21,2009-01-14 13:36:00.000,60, , ,38883,E, ,000,003,052,017,$1,00, ,2009-01-14 13:36:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486638
L12,2009-01-14 13:37:00.000,20, , ,38300,E, ,052,018, , ,IN,00, ,2009-01-14 13:37:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486640
L28,2009-01-14 13:32:00.000,302,38843, ,1890017722010,E,38843, , ,001,156,N,00, ,2009-01-14 13:32:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486642
L14,2009-01-14 13:34:00.000,168, , ,38945,E, ,000,007, , ,IN,00, ,2009-01-14 13:34:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486644
L16,2009-01-14 13:35:00.000,108,1448805, ,1890018498124,E,1448805, , ,001,138,N,00, ,2009-01-14 13:35:00.000, , ,0, ,0,0,0,0,0,0,0,0,0,0,0,14486646

# 9  
Old 01-16-2009
Thanks radoulov, This is perfectly what i need.

Only thing which is missing in this is the deletion part ie, once the file gets copied to output, the records should get deleted.

Thanks so much

I really appreciate your help

Regards,
Sandeep
# 10  
Old 01-16-2009
The code below will generate two files: yes.out and no.out:

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

# 11  
Old 01-16-2009
It generated only one file
# 12  
Old 01-16-2009
Which one?
# 13  
Old 01-18-2009
Hi Thanks so much this WORKs, Actually i was using a wrong file.

I really appreciate for your time on this and also for the knowledge that you have shared

Thanks again and have a great day

Regards,
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