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

Thread Tools Search this Thread
# 1  
Lightbulb Read a flat file, evaluate and create output. UNIX SCRIPT.

Hi all,

I have a flat file as below;


I like to create a Unix script.

The script have to valuate the last two columns, if the values are different the whole line must me added in a new flatfile as an output.

According to the data sample and description the output file must have one line;


Could you please provide me some help in the reading loop and validation?

Thank you all.

Mr. Reds.Smilie
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-19-2012 at 06:22 PM.. Reason: code tags, please!
# 2  
nawk '{a[$0]++} END {for(i in a) if (a[i]==1) print i}' myFile

# 3  
Hi mrreds,

One way using perl:
$ cat infile
$ perl -lne '@f = split /\|+/; printf qq[%s\n], $_ if $f[ $#f - 1 ] != $f[ $#f ]' infile >outfile
$ cat outfile

This User Gave Thanks to birei For This Post:
# 4  
I'm using;


# 5  
Both of the above solutions will work in KSH.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to read through a file and create new users/assign them to groups in Ubuntu

Hi all. I need a shell script that can, in short, read through a text file line by line and create a new user in Ubuntu, as well as assign that user to a group. The format of the text file is not important but preferably: 'username:group'. I don't have much programming knowledge no matter shell... (3 Replies)
Discussion started by: LewisWeekly
3 Replies

2. Shell Programming and Scripting

SQL query in UNIX script - output in flat file

Hi, I never did this before... what I want to do is execute a SQL query from a unix script and redirect sql query's output to a flat file (comma separated one) without the header info (no column names). I would also want not to print the query's output to the screen. snapshot of my script:... (13 Replies)
Discussion started by: juzz4fun
13 Replies

3. Shell Programming and Scripting

How to create a shell script to read a foldername from a text file and go to the folder?

Hi, I am trying to write a shell script which can read folder names from a text file and then go to the folder and picks up a xml file and write on my sipp script so that I can run the sipp script. For example: I have a text file called thelist.txt where I have provided all the folders... (7 Replies)
Discussion started by: pm1504
7 Replies

4. Solaris

How to generate graph from flat file by using unix script

Hi, I need to generate graph from the text file in Unix server. The file contains the following data, Fri Feb 03 07:01:00 PST 2012|3325 Fri Feb 03 07:02:00 PST 2012|3349 Fri Feb 03 07:03:00 PST 2012|3290 Fri Feb 03 07:04:00 PST 2012|3496 Fri Feb 03 07:05:00 PST 2012|3362 Fri Feb 03 07:06:00... (2 Replies)
Discussion started by: gkn
2 Replies

5. UNIX for Dummies Questions & Answers

Verify a flat file with UNIX function or script.

I re-post my question to seek your help and critique. I was required to verify a very large and tab-delimited file, named 'MyFile'. 1. The each line in 'MyFile' has 7 columns, and that the values in the 5th column are integers. I need to use shell functions (and standard LINUX/UNIX filters) to... (1 Reply)
Discussion started by: duke0001
1 Replies

6. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

7. Shell Programming and Scripting

Shell script to email based on flat file output

Hi All, I am a newbee in unix but still have written a shell script which should trigger a mail based on certain conditions but the problem is that my file is not being read. Below is the code please advise. I do not know where is it failing. Note $ and the no followed with it is the no of... (1 Reply)
Discussion started by: apoorva
1 Replies

8. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

9. Shell Programming and Scripting

How to evaluate the value read from a file?

Hi, Could someone please help me with how to do the following? Say I have a flat file test.lst and the content of the file is: Report Date - `date '+%m%d%Y'` I'm trying the following while read myLine do echo ${myLine} done<test.lst This prints Report Date - `date... (1 Reply)
Discussion started by: arunsoman80
1 Replies

10. Shell Programming and Scripting

How To create Flat Files using Unix Shell Script?

Hi all, How to create Flat Files using Unix Shell Script. The Script is supposed to be sheduled to run at a particular time? Thanks in advance Appu (4 Replies)
Discussion started by: Aparna_k82
4 Replies

Featured Tech Videos