Sponsored Content
Top Forums Shell Programming and Scripting Ksh: how compare content of a file with an other array Post 302913468 by jmartin on Sunday 17th of August 2014 12:07:01 PM
Old 08-17-2014
Lightbulb Ksh: how compare content of a file with an other array

Hi,
I created a skript in ksh which generate a file with semicolon as separator, this is an example of the file a created:

example content file:
Code:
hello;AAAA;2014-08-17
hello;BBBB;2014-08-17
hello;CCCC;2014-08-17

I would need to compare the content in of the second column of this file with an array
Example array:
Code:
array[1]=AAAA
array[2]=BBBB
array[3]=CCCC
array[4]=DDDD

If there is some missing values in the file I would need to insert it in the file after the comparison:

in this example would be:
Code:
hello;AAAA;2014-08-17
hello;BBBB;2014-08-17
hello;CCCC;2014-08-17
hello;DDDD;2014-08-17

Could you please help me and show me how can I (in ksh)
1) create an array from a column
2) compare this array with an other array and show the differences

Thx a lot!

Last edited by Franklin52; 08-17-2014 at 01:09 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

compare array contents with file

I have an array "arrA" with the following contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf My data file "Files.dat" has the same contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf I have a script that compares... (0 Replies)
Discussion started by: orahi001
0 Replies

2. Shell Programming and Scripting

file content in an array PERL

Hello everybody, I'm new in this forum. I searched a long time for a solution for my problem but I didn't find the right thing. I have to read from a file (content is "abngjm" without any other signs) and have to write this content in an array. But every sign has to be called by its own... (5 Replies)
Discussion started by: e_prof
5 Replies

3. Shell Programming and Scripting

KSH to group records in a file and compare it with another file

Hi, I've a file like below: DeptFile.csv DeptID EmpID ------- ------ Dep01 Emp01 Dep01 Emp02 Dep01 Emp03 Dep02 Emp04 Dep02 Emp05 I've another file which has EmpFile.csv EmpID Salary ------ ------ (3 Replies)
Discussion started by: Matrix2682
3 Replies

4. Shell Programming and Scripting

KSH: Compare variable to $1 in an input file

Hello, I am working with KSH on AIX and I have 2 files generated from different sources... as seen below: FILE1 FILE2 AAA AAA@ABS0001C BBB BBB@ABS0003D CCC CCC@ABS0023A DDD DDD@ABC0145D EEE EEE@ABS0090A FFF FFF@ABS0002A GGG GGG@ABC0150D HHH FILE1 is main main data source,... (4 Replies)
Discussion started by: right_coaster
4 Replies

5. Shell Programming and Scripting

Print @array content to a file

Hi, as the title, I have an array @f_lines with gene information in it. How can I put the content of @f_lines into a file so that I can read it? I tried this: open(OUTPUT, "file"); # put gene information in this file; @f_lines = ("gene1", "gene2", "gene3"...); # gene information; print... (3 Replies)
Discussion started by: lyni2ULF
3 Replies

6. Shell Programming and Scripting

Compare file to array, replace with corresponding second array

ok, so here is the issue, I have 2 arrays. I need to be able to create a loop that will find ${ARRAY1 in the text doc, and replace it with ${ARRAY2 then write the results. I already have that working. The problem is, I need it to do that same result across however many items are in the 2... (2 Replies)
Discussion started by: gentlefury
2 Replies

7. Shell Programming and Scripting

File names as array element in ksh

Hi, I have an ksh array(ARR). the elements to the array are file names. i need to go to each file in the array and manipulate the records. for name in ${files}; do ---this loop is for all the file names in the array for i in $(wc -l < $name); do --this loop is for all the records in... (20 Replies)
Discussion started by: usrrenny
20 Replies

8. Shell Programming and Scripting

Compare two folders and file content

Hi, I am having two folders where i need to compare the content of files and also to know if any new files been added and redirect the difference output in respective filename logs. For e.g.: Directory D1: f1 f2 f3 Directory D2: f1 f2 f3 f4 i Need to compare the directories... (25 Replies)
Discussion started by: rohit_shinez
25 Replies

9. Shell Programming and Scripting

Compare & print content of file which is not matching

Hi All I want to compare 2 files using awk and get output of content which is not matching I have 2 files a.txt 123 456 780 143 b.txt A|B|C|167|D|E C|K|D|123|D|E A|B|D|789|G|F C|D|G|143|A|B Not matching line from b.txt O/P A|B|C|167|D|E A|B|D|789|G|F (3 Replies)
Discussion started by: aaysa123
3 Replies

10. Shell Programming and Scripting

ksh scripting SSH to Compare File Sizes

Hello, I currently have very little experience with Shell scripting and trying to create a script for the purpose of collecting the size of a couple sizes on 4 different Hosts. The Idea is to collected the information from the files in which the script is kicked off on, store the values into... (17 Replies)
Discussion started by: Abstract3000
17 Replies
Tree::Simple::Visitor::ToNestedArray(3pm)		User Contributed Perl Documentation		 Tree::Simple::Visitor::ToNestedArray(3pm)

NAME
Tree::Simple::Visitor::ToNestedArray - A Visitor for creating nested array trees from Tree::Simple objects. SYNOPSIS
use Tree::Simple::Visitor::ToNestedArray; my $visitor = Tree::Simple::Visitor::ToNestedArray->new(); # given this Tree::Simple tree my $tree = Tree::Simple->new("Root") ->addChildren( Tree::Simple->new("Child1") ->addChildren( Tree::Simple->new("GrandChild1"), Tree::Simple->new("GrandChild2") ), Tree::Simple->new("Child2"), ); # include the trunk (Root) $visitor->includeTrunk(1); # visit the tree $tree->accept($visitor); my $array_tree = $visitor->getResults(); # this then creates the equivalent nested array tree: # [ # 'Root', [ # 'Child1', [ # 'GrandChild1', # 'GrandChild2' # ], # 'Child2' # ] # ] # if you don't include the trunk (Root) then ... $tree->accept($visitor); my $array_tree = $visitor->getResults(); # this then creates the following nested array tree: # [ # 'Child1', [ # 'GrandChild1', # 'GrandChild2' # ], # 'Child2' # ] DESCRIPTION
Given a tree constructed from a Tree::Simple heirarchy, this Visitor will create the equivalent tree of nested arrays. METHODS
new There are no arguments to the constructor the object will be in its default state. You can use the "setNodeFilter" and "includTrunk" methods to customize its behavior. includTrunk ($boolean) Setting the $boolean value to true(1) will cause the node value of the tree's root to be included in the nested array output, setting it to false will do the opposite. setNodeFilter ($filter_function) This method accepts a CODE reference as its $filter_function argument and throws an exception if it is not a code reference. This code reference is used to filter the tree nodes as they are placed into the array tree. The $filter_function is passed a Tree::Simple object, and is expected to return the value desired for inclusion into the array tree. visit ($tree) This is the method that is used by Tree::Simple's "accept" method. It can also be used on its own, it requires the $tree argument to be a Tree::Simple object (or derived from a Tree::Simple object), and will throw and exception otherwise. getResults This method will return the array tree constructed. BUGS
None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it. CODE COVERAGE
See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more inforamtion. SEE ALSO
These Visitor classes are all subclasses of Tree::Simple::Visitor, which can be found in the Tree::Simple module, you should refer to that module for more information. AUTHOR
stevan little, <stevan@iinteractive.com> COPYRIGHT AND LICENSE
Copyright 2004, 2005 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2005-07-14 Tree::Simple::Visitor::ToNestedArray(3pm)
All times are GMT -4. The time now is 10:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy