Sponsored Content
Top Forums Shell Programming and Scripting Match list of strings in File A and compare with File B, C and write to a output file in CSV format Post 302713313 by asnandhakumar on Thursday 11th of October 2012 11:12:12 AM
Old 10-11-2012
File A is joblist.txt
File B is job.log
File C would be an extended log of job.log, which is quite huge for me to upload here.

I have tried the below script and only the list from joblist gets stored in the output file.
Code:
awk '
FILENAME=="joblist.txt" {
for(i=1;i<=NF;i++ ) {Keys[$i]++}
}
FILENAME=="job.log" {
found=0
for(i=1;i<=NF;i++)
{ if(Keys[$i]>0) {found++; }}
if (found != 2 ) {
print $0; found = 0; break;
}
}
' joblist.txt job.log >>diff.csv

---------- Post updated 10-11-12 at 11:12 AM ---------- Previous update was 10-10-12 at 01:05 PM ----------

hello Friends, Can you someone respond to this request.

Last edited by Franklin52; 10-11-2012 at 05:18 AM.. Reason: Please use code tags for data and code samples
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies

2. Shell Programming and Scripting

format output in csv file

I am sending the output of a file to .csv file. The output should look like this: Total Customers Processed:,8 Total Customers Skipped:,0 Total Customers Added:,8 Total Customers Changed:,0 Total Policies Deleted:,0 Total Policies Failed:,0 total:,8 Now i want this output in... (1 Reply)
Discussion started by: Prashant Jain
1 Replies

3. Shell Programming and Scripting

extract strings from file and display in csv format

Hello All, I have a file whose data looks something like this I want to extract just the id, name and city fields in a csv format and sort them by id. Output should look like this. 1,psi,zzz 2,beta,pqr 3,theta,xyz 4,alpha,abc 5,gamma,jkl (12 Replies)
Discussion started by: grajp002
12 Replies

4. Shell Programming and Scripting

Csv format output file using scirpt

Hi All, I get the test result file daily after running the main test script. from the resultfile, need to fetch only server info and status and put them in tabular format in a file and as well in CSV format output file. I tried using awk command but am not able to put them in tabluar... (6 Replies)
Discussion started by: Optimus81
6 Replies

5. 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

6. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

7. Shell Programming and Scripting

Compare two and write updated output in third file

Hi Linux Experts. I have a requirement where i need to update the thousands of table definitions to extend the column length and character set therefore i am looking for some sort of linux script which i can use to update the length and chacterset. I have two files In first file i have 7... (1 Reply)
Discussion started by: Black-Linux
1 Replies

8. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies

9. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

10. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies
File::Policy(3pm)					User Contributed Perl Documentation					 File::Policy(3pm)

NAME
File::Policy - Site policy for file I/O functions SYNOPSIS
use File::Policy; use File::Policy qw/check_safe/; # to import a specific subroutine use File::Policy qw/:all/; # to import all subroutines #Checking I/O policy check_safe($filename, 'r'); check_safe($filename, 'w'); #Preferred directory locations $logdir = get_log_dir(); $tmpdir = get_temp_dir(); DESCRIPTION
This defines the policy for file I/O with modules such as File::Slurp::WithinPolicy. The purpose is to allow systems administrators to define locations and restrictions for applications' file I/O and give app developers a policy to follow. Note that the module doesn't ENFORCE the policy - application developers can choose to ignore it (and systems administrators can choose not to install their applica- tions if they do!). You may control which policy gets applied by creating a File::Policy::Config module with an IMPLEMENTATION constant. You may write your own policy as a module within the File::Policy:: namespace. By default (if no File::Policy::Config is present), the File::Policy::Default policy gets applied which doesn't impose any restrictions and provides reasonable default locations for temporary and log files. The motivation behind this module was a standard, flexible approach to allow a site wide file policy to be defined. This will be most use- ful in large environments where a few sysadmins are responsible for code written by many other people. Simply ensuring that submitted code calls check_safe() ensures file access is sane, reducing the amount of effort required to do a security audit. If your code is not security audit'd, or you are the only developer at your site, this might be overkill. However you may consider it good practise regardless and protection against paths in your code getting corrupted accidently or maliciously in the future. There are two major benefits of using this module. One, sites that do implement a policy can more easily integrate your code in a standard way. If you have a file policy at your site, you can apply different policies (via File::Policy::Config) in different environments (pro- duction, integration test, development) and the appropriate policy is automatically applied without having to change your code or configs. FUNCTIONS
check_safe check_safe( FILENAME , MODE ); Checks FILENAME is safe - dies if not. MODE is r (read) or w (write). get_temp_dir $temporary_directory = get_temp_dir(); Returns the path to temporary directory. Note that any return value will have been cleared of a trailing slash. get_log_dir $log_directory = get_log_dir(); Returns the path to log directory. Note that any return value will have been cleared of a trailing slash. DEFINING YOUR OWN POLICY
To implement your own custom policy cp File/Policy/Default.pm File/Policy/YourPolicy.pm and modify YourPolicy accordingly. Then, create File/Policy/Config.pm contaning: use constant IMPLEMENTATION => 'YourPolicy'; Now having used File::Policy, calling check_safe in your scripts will enforce your policy (as well as give you access to log and temp paths in locations you recommend). SEE ALSO
File::Policy::Default, Safe VERSION
$Revision: 1.5 $ on $Date: 2005/05/18 15:58:21 $ by $Author: johna $ AUTHOR
John Alden <cpan _at_ bbc _dot_ co _dot_ uk> COPYRIGHT
(c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt perl v5.8.8 2005-06-15 File::Policy(3pm)
All times are GMT -4. The time now is 05:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy