Sponsored Content
Top Forums Shell Programming and Scripting KSH: Compare variable to $1 in an input file Post 302422846 by right_coaster on Wednesday 19th of May 2010 03:32:02 PM
Old 05-19-2010
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:

Code:
FILE1 FILE2
AAA AAA@ABS0001C
BBB BBB@ABS0003D
CCC CCC@ABS0023A
DDD DDD@ABC0145D
EEE EEE@ABS0090A
FFF FFF@ABS0002A
GGG GGG@ABC0150D
HHH

[note FILE1 is noted above by the 3 characters, FILE2 is everything after the space]

FILE1 is main main data source, created daily and changes quite frequently. FILE2 is static and requires manual update. Each record in FILE1 will match the characters before the @ symbol in FILE2. However, at times, FILE1 may have more records than FILE2 and there will be no match. Rarely, FILE1 will contain less records than FILE2

I need a way to take the value of each line in FILE1 and search for it in FILE2... if found, then I need to print the record from FILE1 with the text after the @ symbol in FILE2. If no match found, I need to print "NULL"

Example output:
Code:
AAA ABS0001C
BBB ABS0003D
CCC ABS0023A
DDD ABC0145D
EEE ABS0090A
FFF ABS0002A
GGG ABC0150D
HHH NULL

I'm able to put the static file within my script in the form of a giant case statement, but that is really not a feasible approach as there are 200+ records in the file. I also think I could do this with a few nasty loops, but I'm really looking for an efficient practical approach. Thanks for any help you can give...

Last edited by Scott; 05-19-2010 at 04:35 PM.. Reason: Code tags please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help reading an input file in KSH

First I' d like to say you guys are awesome. :) I have a word document that I cut and paste into Textpad and it removed all the fancy formatting which is fine with me. I WinScp'd it to the box and and called it inputfile.txt. Opened it in vi and don't see any special characters or stuff that... (2 Replies)
Discussion started by: zilla30066
2 Replies

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

3. Shell Programming and Scripting

Unzip the input file using shell script (ksh)

Hi, I need help in unziping input file through shell script. I had written script, which checks for input file extention. If Extension is "zip" or "gz", then I want to do unzip/uncompress that file. Caould you please let me know that, How to unzip a file through shell script (ksh). Thanks... (16 Replies)
Discussion started by: Poonamol
16 Replies

4. Shell Programming and Scripting

KSH - How to use a file as input to an IF or AWK statement

Hi, I have a ksh script where I have an awk statement to exclude a few items... but my "few items" has now grown substantially and I'm looking for a nice compact way of doing this. Maybe putting the exceptions into a file or something? Any suggestions greatly appreciated. # Excluded items... (1 Reply)
Discussion started by: right_coaster
1 Replies

5. Shell Programming and Scripting

KSH - Text from input file truncated while converting it to excel

Dear Members, I am using the attached script to convert a input file delimited by '|' to excel. However, while processing the attribute change_reason, the whole content of the text under change_reason is not displayed completely in the cell in excel. It is truncated after only first few words.... (1 Reply)
Discussion started by: Yoodit
1 Replies

6. Shell Programming and Scripting

[KSH] Creating automatic variable from read input

Hello there, I am posting to seek help with a KSH script, I am making a simple calculation program where the user can enter as many numbers as they like, I am getting their input using the read command, however I am not sure how to repeat doing this and storing the input in to new variables... (7 Replies)
Discussion started by: pandapowerbox
7 Replies

7. Shell Programming and Scripting

ksh using input file with output going to same file name and location

I've been asked if I can write a "quick" little ksh script that will do the following: java java_class_file /dir/input_file.xml /dir/output_file.xml I'm a complete newbie with ksh so any help would be appreciated. This is on AIX and java is found in /usr/java5/jre/bin/java (4 Replies)
Discussion started by: newbie_ksh
4 Replies

8. Shell Programming and Scripting

XML variable for input in same input file

Dear All , i stuck in one problem executing xml .. i have input xml as <COMMAND name="ARRANGEMENT.WRITE" timestamp="0" so="initial"> <SVLOBJECT> <LONG name="CSP_PMNT_ID" val="-1"/> <MONEY name="CSP_CEILING" amount="0.0" currency="AUD"/> ... (6 Replies)
Discussion started by: arvindng
6 Replies

9. Shell Programming and Scripting

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: 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... (3 Replies)
Discussion started by: jmartin
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
JOIN(1) 								FSF								   JOIN(1)

NAME
join - join lines of two files on a common field SYNOPSIS
join [OPTION]... FILE1 FILE2 DESCRIPTION
For each pair of input lines with identical join fields, write a line to standard output. The default join field is the first, delimited by whitespace. When FILE1 or FILE2 (not both) is -, read standard input. -a SIDE print unpairable lines coming from file SIDE -e EMPTY replace missing input fields with EMPTY -i, --ignore-case ignore differences in case when comparing fields -j FIELD (obsolescent) equivalent to `-1 FIELD -2 FIELD' -j1 FIELD (obsolescent) equivalent to `-1 FIELD' -j2 FIELD (obsolescent) equivalent to `-2 FIELD' -o FORMAT obey FORMAT while constructing output line -t CHAR use CHAR as input and output field separator -v SIDE like -a SIDE, but suppress joined output lines -1 FIELD join on this FIELD of file 1 -2 FIELD join on this FIELD of file 2 --help display this help and exit --version output version information and exit Unless -t CHAR is given, leading blanks separate fields and are ignored, else fields are separated by CHAR. Any FIELD is a field number counted from 1. FORMAT is one or more comma or blank separated specifications, each being `SIDE.FIELD' or `0'. Default FORMAT outputs the join field, the remaining fields from FILE1, the remaining fields from FILE2, all separated by CHAR. AUTHOR
Written by Mike Haertel. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for join is maintained as a Texinfo manual. If the info and join programs are properly installed at your site, the command info join should give you access to the complete manual. join (coreutils) 4.5.3 February 2003 JOIN(1)
All times are GMT -4. The time now is 03:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy