Sorting with sed,awk ...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting with sed,awk ...
# 8  
Old 01-21-2010
Thanks! Excellent, it worked.

---------- Post updated at 04:42 AM ---------- Previous update was at 02:56 AM ----------

How can i get this output:
Code:
RXOCF-8 CFCLASS 2A:57 CFRU:40
RXORX-8-0 RXCLASS 1B:23 RXCLASS 1B:45 RXCLASS 1B:16
RXORX-8-1 RXEXTERNAL CLASS 2A:6 
RXOCF-21
RXOTX-34-1 TXCLASS 1B:2

# 9  
Old 01-21-2010
Quote:
Originally Posted by aydj

How can i get this output:
Code:
RXOCF-8 CFCLASS 2A:57 CFRU:40
RXORX-8-0 RXCLASS 1B:23 RXCLASS 1B:45 RXCLASS 1B:16
RXORX-8-1 RXEXTERNAL CLASS 2A:6 
RXOCF-21
RXOTX-34-1 TXCLASS 1B:2

I would try to fix the program that generates the original output ...
# 10  
Old 01-21-2010
@ Alister

can you help generate an output that looks like that of aydj:

input:
ELGBS17 RXOTRX-10-6 FAULT CODE 2A
ELGBS17 RXOTRX-10-6 43
ELGBS17 RXOTRX-10-6 RU
ELGBS17 RXOTRX-10-6 0
ELGBS17 RXOTRX-218-5 FAULT CODE 2A
ELGBS17 RXOTRX-218-5 43
ELGBS17 RXOTRX-218-5 RU
ELGBS17 RXOTRX-218-5 0
EOGBS01 RXOCF-111 FAULT CODE 2A
EOGBS01 RXOCF-111 57
EOGBS01 RXOCF-111 RU
EOGBS01 RXOCF-111 40
EOGBS01 RXOCF-33 FAULT CODE 2A
EOGBS01 RXOCF-33 57
EOGBS01 RXOCF-33 RU
EOGBS01 RXOCF-33 40
EOGBS01 RXOCF-38 FAULT CODE 2A
EOGBS01 RXOCF-38 33 57
EOGBS01 RXOCF-38 RU
EOGBS01 RXOCF-38 40
EOGBS01 RXOCF-50 FAULT CODE 2A
EOGBS01 RXOCF-50 33 57
EOGBS01 RXOCF-50 RU
EOGBS01 RXOCF-50 40
EOGBS01 RXOCF-64 FAULT CODE 2A
EOGBS01 RXOCF-64 33 57
EOGBS01 RXOCF-64 RU
EOGBS01 RXOCF-64 40

output:

ELGBS17 RXOTRX-10-6 FAULT CODE 2A:43 RU 0
ELGBS17 RXOTRX-218-5 FAULT CODE 2A:43 RU 0
EOGBS01 RXOCF-111 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-33 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-38 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-50 FAULT CODE 2A:33 2A:57 RU 40
EOGBS01 RXOCF-64 FAULT CODE 2A:33 2A:57 RU 40

Thanks in Advance
# 11  
Old 01-22-2010
Quote:
Originally Posted by aydj
Thanks! Excellent, it worked.

---------- Post updated at 04:42 AM ---------- Previous update was at 02:56 AM ----------

How can i get this output:
Code:
RXOCF-8 CFCLASS 2A:57 CFRU:40
RXORX-8-0 RXCLASS 1B:23 RXCLASS 1B:45 RXCLASS 1B:16
RXORX-8-1 RXEXTERNAL CLASS 2A:6 
RXOCF-21
RXOTX-34-1 TXCLASS 1B:2

Code:
$ cat aydj.awk
function p() {if (s) {gsub(/  +/, " ", s); print s}}
/^RXO/ {p(); s=$1;b=substr($1,4,2); next}
/CLASS/ {c=b$0; getline; gsub(/[^ ]+/, c":&"); s=s" "$0; next}
/^RU/ {s=s b $0":";next}
{s=s" "$0}
END {p()}

$ awk -f aydj.awk data
RXOCF-8 CFCLASS 2A:57 CFRU: 40
RXORX-8-0 RXCLASS 1B:23 RXCLASS 1B:45 RXCLASS 1B:16
RXORX-8-1 RXEXTERNAL CLASS 2A:6
RXOCF-21
RXOTX-34-1 TXCLASS 1B:2



---------- Post updated 01-22-10 at 12:29 AM ---------- Previous update was 01-21-10 at 11:59 PM ----------

Quote:
Originally Posted by jagannaja
@ Alister

can you help generate an output that looks like that of aydj:

input:
ELGBS17 RXOTRX-10-6 FAULT CODE 2A
ELGBS17 RXOTRX-10-6 43
ELGBS17 RXOTRX-10-6 RU
ELGBS17 RXOTRX-10-6 0
ELGBS17 RXOTRX-218-5 FAULT CODE 2A
ELGBS17 RXOTRX-218-5 43
ELGBS17 RXOTRX-218-5 RU
ELGBS17 RXOTRX-218-5 0
EOGBS01 RXOCF-111 FAULT CODE 2A
EOGBS01 RXOCF-111 57
EOGBS01 RXOCF-111 RU
EOGBS01 RXOCF-111 40
EOGBS01 RXOCF-33 FAULT CODE 2A
EOGBS01 RXOCF-33 57
EOGBS01 RXOCF-33 RU
EOGBS01 RXOCF-33 40
EOGBS01 RXOCF-38 FAULT CODE 2A
EOGBS01 RXOCF-38 33 57
EOGBS01 RXOCF-38 RU
EOGBS01 RXOCF-38 40
EOGBS01 RXOCF-50 FAULT CODE 2A
EOGBS01 RXOCF-50 33 57
EOGBS01 RXOCF-50 RU
EOGBS01 RXOCF-50 40
EOGBS01 RXOCF-64 FAULT CODE 2A
EOGBS01 RXOCF-64 33 57
EOGBS01 RXOCF-64 RU
EOGBS01 RXOCF-64 40

output:

ELGBS17 RXOTRX-10-6 FAULT CODE 2A:43 RU 0
ELGBS17 RXOTRX-218-5 FAULT CODE 2A:43 RU 0
EOGBS01 RXOCF-111 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-33 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-38 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-50 FAULT CODE 2A:33 2A:57 RU 40
EOGBS01 RXOCF-64 FAULT CODE 2A:33 2A:57 RU 40

Thanks in Advance
Code:
$ cat jagannaja.awk
function p() {if (t) {gsub(/  +/, " ", t); print t}}
/CODE/ {p(); s=$NF;$NF="";t=$0;getline;{for (i=3;i<=NF;i++) t=t" "s":"$i };next}
{t=t" "$NF}
END {p()}

$ awk -f jagannaja.awk input
ELGBS17 RXOTRX-10-6 FAULT CODE 2A:43 RU 0
ELGBS17 RXOTRX-218-5 FAULT CODE 2A:43 RU 0
EOGBS01 RXOCF-111 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-33 FAULT CODE 2A:57 RU 40
EOGBS01 RXOCF-38 FAULT CODE 2A:33 2A:57 RU 40
EOGBS01 RXOCF-50 FAULT CODE 2A:33 2A:57 RU 40
EOGBS01 RXOCF-64 FAULT CODE 2A:33 2A:57 RU 40

# 12  
Old 01-24-2010
Thanks, it's working.
# 13  
Old 01-24-2010
@Alister,

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting content between match pattern and move on with awk and sed

S 0.0 0.0 (reg, inst050) k e f d c S 0.0 0.0 (mux, m030) k g r s x v S 0.0 0.0 (reg, inst020) q s n m (12 Replies)
Discussion started by: ctphua
12 Replies

2. Shell Programming and Scripting

Help with awk sorting with different values

Hello, I have a file as follows: BTA Pos KLD 4 79.7011 5.7711028907 4 79.6231 5.7083918219 5 20.9112 4.5559494707 5 58.0002 3.4423546273 6 38.2569 4.7108176788 6 18.3889 7.3631759258 (1 Reply)
Discussion started by: Homa
1 Replies

3. Shell Programming and Scripting

Sorting within a record using AWK

Hello, I have a file which has the following format: I have to do is sort individual records in the file based on the 4th field. Each record starts with "Module". Is there an easy way to do this using awk. I have tried piping output from awk to sort and also using "sort" inside awk but... (8 Replies)
Discussion started by: fifteate
8 Replies

4. Shell Programming and Scripting

Sorting a .csv using awk or other

Hello all, I am new here and *relatively* new to Unix. I have a bit of an emergency. I have a three column file that I need to sort: sample name, miRNA, reads per million (RPM) There are multiple samples, and for each sample name there are multiple miRNAs and associated RPMs. Some of these... (6 Replies)
Discussion started by: dunnybocter
6 Replies

5. Shell Programming and Scripting

sed sorting command explanation

sed '$!N; /^\(.*\)\n\1$/!P; D' i found this file which removes duplicates irrespective for sorted or unsorted file. keep first occurance and remove the further occurances. can any1 explain how this is working.. i need to remove duplicates following file. duplicate criteria is not the... (3 Replies)
Discussion started by: mukeshguliao
3 Replies

6. Shell Programming and Scripting

AWK, sorting-if and print help.

Little-bit of awk experience, need some of the expert help on here. Browsed around here, got a little further, but I am still missing some pieces. Can you help me fill-in my missing awk cells? Sample data file (leaving out ","'s): Column 1 Column 2 Column 3 Column 4 ... (10 Replies)
Discussion started by: boolean2222
10 Replies

7. Shell Programming and Scripting

Is there any better way for sorting in bash/awk

Hi, I have a file which is:- 1 6 4 8 2 3 2 1 9 3 2 1 3 3 5 6 3 1 4 9 7 8 2 3 I would like to sort from field $2 to field $6 for each of the line to:- 1 2 3 4 6 8 2 1 1 2 3 9 3 1 3 3 5 6 4 2 3 7 8 9 I came across this Arrays on example 26-6. But it is much complicated. I am... (7 Replies)
Discussion started by: ahjiefreak
7 Replies

8. UNIX for Advanced & Expert Users

Horizontal sorting of lines in a File: SED implementation?

Hi guys, Do you know how can I sort a file horizontally per line??? sample input file: zebra papa dog apple yahoo kangaroo ape sample output: apple dog papa zebra ape kangaroo yahoo Please post if u know the sed implementation of this (or whatever implementation u may know of)... (7 Replies)
Discussion started by: marlonus999
7 Replies

9. Shell Programming and Scripting

sorting in awk

i have following file have following type of data 1~%%~fcashfafh~%%~9797 can i sort(numeric) the file on first field and then on last feild using awk (3 Replies)
Discussion started by: mahabunta
3 Replies

10. Shell Programming and Scripting

awk sorting

Hi, I have used the following code to sort two sets of data: awk '{printf "%10s %s\n",$1,$2}' The first column is text and the second involves numbers. I was just wondering how i would go about sorting the second number so that they ascend from the top? Thanks for any help (4 Replies)
Discussion started by: Jaken
4 Replies
Login or Register to Ask a Question