verify ordered records


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users verify ordered records
# 1  
Old 01-21-2011
verify ordered records

I need to resolve next problem, I have a unix txt file,
I need to verify that it is to ordered for a key , in this case CUSTOMER, I need to do it with awk , it is shows an example

Code:
 
Incorrect                   Correct
CUSTOMER PRODUCT   CUSTOMER PRODUCT
1             |01             1  |01
2             |02             1  |03
1             |03             1  |04 
1             |04             1  |05
3             |04             2  |02
1             |05             1  |05

many thank

Last edited by joeyg; 01-21-2011 at 12:50 PM.. Reason: Please use CODETAGE
# 2  
Old 01-21-2011
Why the 'awk' requirement?

Very easy to do, and several ways to accomplish.
But, why the requirement for 'awk'?
Whenever I see a question with a solution requirement, it makes me think that it is homework.

Please explain the real-world issue here, or post this in the Homework Forum.
# 3  
Old 01-21-2011
Thank for answer. my enterprise solicited validate a txt file in unix, but this file must be ordered , if it is not ordered, not validate
the solution too can be other unix command,
thank
# 4  
Old 01-21-2011
OK...

Is your input file like
Code:
$ cat sample3.txt
1|01
2|05
1|02
3|04
1|05
1|04
2|04

Then output could be sorted such as:
Code:
$ sort sample3.txt
1|01
1|02
1|04
1|05
2|04
2|05
3|04

# 5  
Old 01-21-2011
I do not want to sort the file, just want to make sure it is neat, if not ordered not to continue the validation process, it is understood, I think I explained very well
sorry

many thanks
# 6  
Old 01-21-2011
Define
Quote:
make sure it is neat
I can make a drink "neat", but that means "no ice". Ha ha
# 7  
Old 01-21-2011
Try:
Code:
awk 'NR>2 && $1+0<p{exit 1}{p=$1+0}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep only specific lines ordered by column/date

Hi everybody, I'd like to think I've been through the search tool not only on this site, but also on google too, but I haven't been able to find what I was looking for. If I might've missed something on this forum, please slap me in the face with a link that you consider useful for my query :D ... (4 Replies)
Discussion started by: dilibau
4 Replies

2. UNIX for Dummies Questions & Answers

make ls retrive ordered list of elements

Hello friends!! I have a question regarding the use of ls in unix. I have a folder with files: t1.txt t2.txt t3.txt t4.txt ... t10.txt When I make an ls I always get: t10.txt t1.txt t2.txt t3.txt .. t9.txt (2 Replies)
Discussion started by: SaktiPhoenix
2 Replies

3. Shell Programming and Scripting

sed replace values of column with ordered numbering

Hello, I am trying to write a shell script that will create a gnuplot file. My main problem is that I have a data file with two columns: 1.05929120E+09 5.0000701214792 1.05930096E+09 5.00006386985764 1.05930584E+09 5.00019465404908 1.05931072E+09 5.00031960589719 ... (2 Replies)
Discussion started by: pau
2 Replies

4. What is on Your Mind?

I just ordered a Mini-Box with no fan!

I just ordered a Mini-Box M350 with a Mini-ITX Intel DM510MO motherboard. NO FAN! I've come to hate the wine of spinning mechanisms in PCs in my quiet home. This one is for surfing the web in my living room (instead of using this laptop), so it doesn't really need much power. If I do... (1 Reply)
Discussion started by: KenJackson
1 Replies

5. Shell Programming and Scripting

Merge 3 files in 1 file in an ordered way

Hi, I have a question that I cannot solve. if I have a file like this (lets say "x-values.dat"): x1 x2 x3 another file like this (lets say "y-values.dat"): y1 y2 y3 y4 and another file like this (lets say "p-values.dat"): p1 p2 p3 ... p12 How can I get this output? x1 y1 p1 x1 y2... (16 Replies)
Discussion started by: lego
16 Replies

6. Shell Programming and Scripting

Print is not in ordered after hash converted to array

Perl: Can anyone tell me why after I convert the hash into an array, when I print it out, it's not in the order like the hash? See below.. my %cityZip = ("Logan, AL", 35098, "Los Angeles, CA", 90001, "OrangeVille, IL", 61060, "Palm Bay, FL",... (6 Replies)
Discussion started by: teiji
6 Replies

7. Shell Programming and Scripting

Script to unorder an ordered list

Wondering if someone could help me with this in any scripting/programming language. I have a list of ordered IP addresses and I want to unorder them. So for example, if I had a file like this: 111.111.111.110 111.111.111.111 111.111.111.112 111.111.111.113 111.111.111.114 I would want to... (4 Replies)
Discussion started by: kerpm
4 Replies

8. Shell Programming and Scripting

merging two file in an ordered way

actually, it seems somewhat confusing.. let me clearify it i want a file having all the attributes produced by ls -lc command. i want to add one more thing i.e. time of last access to a file attribute. so how can i merge these two things in a single file in a columnar way. i tried with these... (2 Replies)
Discussion started by: raku05
2 Replies
Login or Register to Ask a Question