Sponsored Content
Top Forums Shell Programming and Scripting AWK, sorting-if and print help. Post 302344296 by boolean2222 on Saturday 15th of August 2009 04:24:38 PM
Old 08-15-2009
Input:
Code:
Col1	Col2	Col3	Col4	Col5	Col6	Col7	Col8	Col9
apple1-123856	banana12	shaws	fruit	food	4:20:00 PM 8/18/2008	type2	 12.122.122.122	00:00:00:00:00:00
apple1-123856	banana12	shaws	fruit	food	4:21:00 PM 8/18/2008	type3	 12.122.122.123	00:00:00:00:00:01
apple3-123656	banana34	shaws	fruit	food	4:24:00 PM 8/18/2008	type5	 12.122.122.125	00:00:00:00:00:09
apple3-123656	banana34	shaws	fruit	food	4:21:00 PM 8/18/2008	type6	 12.122.122.126	00:00:00:00:00:08
banana1-127456	banana77	shaws	fruit	food	4:23:00 PM 8/18/2008	type2	 12.122.122.122	00:00:00:00:00:10
banana2-133456	banana88	shaws	fruit	food	10:24:00 PM 8/18/2008	type2	 12.122.122.122	00:00:00:00:00:11

Output:
Code:
<name="apple1-123856.forapples" id="banana12" type="shaws" type1="fruit food" date="20080818">	
<subdata="type2" ip="12.122.122.122" mac="00:00:00:00:00:00" />
<subdata="type3" ip="12.122.122.123" mac="00:00:00:00:00:01" />
</name>
<name="apple3-123656.forapples" id="banana34" type="shaws" type1="fruit food" date="20080818">	
<subdata="type5" ip="12.122.122.125" mac="00:00:00:00:00:09" />
<subdata="type6" ip="12.122.122.126" mac="00:00:00:00:00:08" />
</name>
<name="banana1-127456.forbananas" id="banana77" type="shaws" type1="fruit food" date="20080818">	
<subdata="type2" ip="12.122.122.122" mac="00:00:00:00:00:10" />
</name>
<name="banana2-133456.forbananas" id="banana88" type="shaws" type1="fruit food" date="20080818">	
<subdata="type2" ip="12.122.122.122" mac="00:00:00:00:00:11" />
</name>

extra notes:
-if apple = .forapples
-if banana = .forbananas
-if id's are the same, the subdata (last 3 columns) are used

Last edited by boolean2222; 08-15-2009 at 06:14 PM.. Reason: i can't get it right! now, let's hope.
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

How do I get awk to print a " in it's print part?

The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }' I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ". Thanks. (2 Replies)
Discussion started by: LordJezo
2 Replies

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

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

5. Shell Programming and Scripting

Sorting with sed,awk ...

I need to sort this input using sed, awk or any other tool to give below output Input: RXOCF-8 CLASS 2A 57 RU 40 RXORX-8-0 CLASS 1B 23 45 16 RXORX-8-1 EXTERNAL CLASS 2A (12 Replies)
Discussion started by: aydj
12 Replies

6. Shell Programming and Scripting

Sorting inside awk

I have an array with five columns and i want to write it to a file. Before writing it i must sort it using the field in the fifth column. _________________________________________ |field 1|field 2|field 3|field 4|field 5| | | | | | | | | | |... (6 Replies)
Discussion started by: beatblaster666
6 Replies

7. Shell Programming and Scripting

AWK/GREP sorting help

hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this; 192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible sort... (8 Replies)
Discussion started by: sam127
8 Replies

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

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

10. 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
diff3(1)						      General Commands Manual							  diff3(1)

NAME
diff3 - Compares three files SYNOPSIS
diff3 [-e | -x | -E | -X | -3] file1 file2 file3 The diff3 command reads three versions of a file and writes to standard output the ranges of text that differ. OPTIONS
Creates an edit script for use with the ed command to incorporate into file1 all changes between file2 and file3 (that is, the changes that normally would be flagged ==== and ====3). Produces an edit script to incorporate only changes flagged ====. These are similar to -e and -x, respectively, but treat overlapping changes (that is, changes that are flagged ==== in the normal listing) differently. The overlap- ping lines from both files are inserted by the edit script, bracketed by <<<<<< and >>>>>> lines. The -E option is used by RCS merge to ensure that overlapping changes in the merged files are preserved and brought to someone's attention. Produces an edit script to incorpo- rate only changes flagged ====3. DESCRIPTION
The diff3 command reads three versions of a file and writes to standard output the ranges of text that differ, flagged with the following codes: All three files differ. file1 differs. file2 differs. file3 differs. The type of change needed to convert a given range of a given file to match another file is indicated in one of these two ways in the out- put: Text is to be added after line number number1 in file, where file is 1, 2, or 3. Text in the range line number1 to line number2 is to be changed. If number1 = number2, the range may be abbreviated to number1. The original contents of the range follow immediately after a c indication. When the contents of two files are identical, diff3 does not show the contents of the lower-numbered file, although it shows the location of the identical lines for each. NOTES
Editing scripts produced by the -e option cannot create lines consisting only of a single . (dot). EXAMPLES
To list the differences among three files, enter: diff3 fruit.a fruit.b fruit.c fruit.a, fruit.b, and fruit.c contain the following data: fruit.a: banana grape kiwi lemon mango orange peach pare fruit.b: apple banana grapefruit kiwi orange peach pear fruit.c: grape grapefruit kiwi lemon mango orange peach pear The output from diff3 shows the differences between these files as follows. (The comments on the right do not appear in the output.) ==== All three files are different. 1:1,2c - Lines 1 and 2 of the first file, fruit.a banana grape 2:1,3c - Lines 1 through 3 of fruit.b apple banana grapefruit 3:1,2c - Lines 1 and 2 of fruit.c grape grapefruit ====2 The second file, fruit.b, is different. 1:4,5c - Lines 4 and 5 are the same in fruit.a and fruit.c. 2:4a 3:4,5c - To make fruit.b look the same, add text after line 4. lemon mango ====1 The first file, fruit.a, is different. 1:8c pare 2:7c - Line 7 of fruit.b and line 8 of fruit.c are the same. 3:8c pear FILES
Helper program. SEE ALSO
Commands: bdiff(1), cmp(1), comm(1), diff(1), ed(1) diff3(1)
All times are GMT -4. The time now is 03:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy