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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH - How to use a file as input to an IF or AWK statement
# 1  
Old 05-09-2011
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.
Code:
# Excluded items
JOB1=DW801P
JOB2=DW801P_SP
JOB3=DW803P
JOB4=DW803P_SP

# Results from another command are being piped to this awk statement.
Code:
awk '{if ($4 != "'"$DATE"'" && $2 != "'"$JOB1"'" && $2 != "'"$JOB2"'" && $2 != "'"$JOB3"'" && $2 != "'"$JOB4"'") print $1" "$2" "$4}' >> $FILE

Excluded items has grown to over 30...

Thanks!

Last edited by Franklin52; 05-09-2011 at 03:13 PM.. Reason: Please use code tags
# 2  
Old 05-09-2011
Code:
awk 'BEGIN {        while(getline <"filename") REJECT[N++]=$0 }
{
        p=1;
        for(M=0; p&&(M<N); M++)
        if($4 == REJECT[M]) p=0;
        if(p) print ...
}' filename2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh - Read input from file and output CSV i same row

Hello I have the following output and want the output to look: FROM: GigabitEthernet0/0 is up, line protocol is up 1 input errors, 0 CRC, 0 frame, 1 overrun, 0 ignored 275 output errors, 0 collisions, 3 interface resets GigabitEthernet0/1 is up, line protocol is up 0... (4 Replies)
Discussion started by: JayJay2018
4 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. UNIX for Dummies Questions & Answers

How to pass cat file in awk statement?

Hi, I am working on kernel parameters, want to check values under /proc/sys/kernel below I tried for kernel.sem SEMMNS: 4096 cat /proc/sys/kernel/sem | awk '{print $2}' awk '{ if ($2 < 33000) print }' /proc/sys/kernel/sem |awk '{print $2}' 32000 The above... (7 Replies)
Discussion started by: stew
7 Replies

4. Shell Programming and Scripting

Help with awk statement to format text file.

Hello, I am fairly new to shellscripting and have written a script to check on messages file and report failed logins: Here is the original file: Jul 17 03:38:07 sfldmilx086 sshd: error: PAM: Authentication failure for houghn97 from 10.135.77.201 Jul 17 03:38:07 sfldmilx086 sshd: error:... (2 Replies)
Discussion started by: neilh1704
2 Replies

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

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

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

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

9. Shell Programming and Scripting

Awk output to file in IF statement

Hi all, I currently have the following script in 1) which outputs to a file if the 3rd column is equal to the message_id value. This works. However what I want to do is incorporate an else statement and output to a different file if the 3rd column doesnt equal the message_id values. I tried that... (7 Replies)
Discussion started by: Donkey25
7 Replies

10. 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
Login or Register to Ask a Question