Help with UNIX script --Read from one file and delete entries in other


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with UNIX script --Read from one file and delete entries in other
# 8  
Old 03-19-2014
Quote:
Originally Posted by Samingla
Hi Yoda,

Below is the code that I am using to delete a section of records from a file if the section has a constant value.
Code:
awk '!/(^|\n)xyz: true/' RS='' ORS='\n\n' sample_delete.txt

But now my search criteria is changing for each line and I do not have an idea on how to do that.

Thanks,
Sam
In case it interests you, the following is a solution which builds on your multiline-record approach:
Code:
awk 'FNR==NR {a[$0]; next} !($1 in a)' file2 FS='\n' RS='' ORS='\n\n' file1

If there will never be any whitespace in the values and if any amount of whitespace beyond a single blank is equivalent to a single blank, you can simplify a bit:
Code:
awk 'FNR==NR {a[$2]; next} !($2 in a)' file2 RS= ORS='\n\n' file1

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to delete old entries from a file

I need to remove the file entries that are 30 days old. I have a file with the below data. 111.XX.XX.99 - - "GET /folder1/wp-content" 304 111.XX.XX.99 - - "GET /folder1/wp-content" 304 111.XX.XX.99 - - "GET /folder1/wp-content" 304 111.XX.XX.99 - - "GET /folder1/wp-content" 304... (5 Replies)
Discussion started by: anil510
5 Replies

2. UNIX for Dummies Questions & Answers

Read a flat file, evaluate and create output. UNIX SCRIPT.

Hi all, I have a flat file as below; 470423495|1||TSA-A000073800||1|||1 471423495|1||TSA-A000073800||5|||5 472423495|1||TSA-A000073800||2|||7 473423495|1||TSA-A000073800||3|||3 I like to create a Unix script. The script have to valuate the last two columns, if the values are... (4 Replies)
Discussion started by: mrreds
4 Replies

3. UNIX and Linux Applications

Perl Script to read an excel file into an array and search in the UNIX directories

Hi, I want the Perl script with versions 5.8.2 and 5.8.5 starting with #!/usr/bin/perl The Perl program should read the excel file or text file line by line and taking into an array and search in the UNIX directories for reference file of .jsp or .js or .xsl with path .The Object names... (2 Replies)
Discussion started by: pasam
2 Replies

4. Shell Programming and Scripting

Unix Script to read the XML file from Website

Hi Experts, I need a unix shell script which can copy the xml file from the below pasted website and paste in in my unix directory. http://www.westpac.co.nz/olcontent/olcontent.nsf/fx.xml Thanks in Advance... (8 Replies)
Discussion started by: phani333
8 Replies

5. Shell Programming and Scripting

HP Unix Script to Delete the lines in a file

Hi Experts, I have a file format as mentioned below. I would like to have unix script (HP Unix) which can: 1. Remove first 6 and last 3 lines. 2. Delete the lines where 3rd column having Alpha Numeric Number 3. Delete the lines where 4th column having 0.00 4. Calculate the sum of all the... (16 Replies)
Discussion started by: phani333
16 Replies

6. Shell Programming and Scripting

Delete lines from file using Unix Script

Hi Experts, I have a file in the below given format. First two lines are header and Trailer. Rest all are transaction Lines. I have to delete all other lines except first line (Header) and lines which contains 5000 in 1st column and 0 in 5th column. Can anyone please kindly provide me with... (6 Replies)
Discussion started by: phani333
6 Replies

7. Shell Programming and Scripting

Unix script help to read log file

Hi I have a big log file :08,936 DEBUG HttpConnectionManager.getConnection: config = 11:39:08,936 DEBUG Getting free connection, 11:39:08,989 DEBUG Freeing connection, hostConfig=HostConfiguration 11:39:08,989 DEBUG Notifying no-one, there are no waiting threads 11:39:09,046... (4 Replies)
Discussion started by: javaholics
4 Replies

8. Shell Programming and Scripting

Need Script to delete multiple entries from a file

I am new to Linux and would appreciate some help. I need a script to do the following: My file contains the following entries more file 1 1 1 1 2 2 2 I want to delete multiple entries of 1 and 2 and just keep one of each. The output should look like more file 1 2 Thanks (1 Reply)
Discussion started by: sidewayz
1 Replies

9. UNIX for Dummies Questions & Answers

File read/delete synchronization in unix

Hi, I have 2 processes that will be accessing the same file. First process first reads from the file, closes it and then opens it again to write to it (this is done sequentially). The second process may delete the file on some condition. These processes are independent of each other now. What... (2 Replies)
Discussion started by: saumya.c
2 Replies

10. UNIX for Dummies Questions & Answers

file read + unix script

hi, how can i read line by line from a file using unix shalle script? Thanks and Regards Vivek.S (2 Replies)
Discussion started by: vivekshankar
2 Replies
Login or Register to Ask a Question