Sponsored Content
Top Forums Shell Programming and Scripting Sort two columns with alphanumeric values horizontally Post 303001048 by RavinderSingh13 on Tuesday 25th of July 2017 11:40:48 PM
Old 07-26-2017
Hello sammy777888,

Considering that your Input_file is same as shown sample Input_file, if that is the case then following may help you in same.
Code:
awk -F"\t" '{sub(/ /,"",$3);split($3,a,"|");q=a[2];v=a[3];sub(/[0-9]+/,"",q);sub(/[0-9]+/,"",v);if(a[2]+0>a[3]+0){tmp=a[2]+0;a[2]=a[3]+0;a[3]=tmp+0};$3=sprintf("%s|%d%s%s|%d%s%s",a[1],a[2]+0,length(a[2]+0)>2?"":" ",q,a[3]+0,length(a[3]+0)>2?"":" ",v)}1' OFS="\t"  Input_file

Output will be as follows.
Code:
aa      bb      dmns|756dmns|860ee      ff
aa      bb      dmns|260dmns|310ee      ff
aa      bb      dmns|77 dmns|110ee      ff
aa      bb      dmns|756dmns|860ee      ff
aa      bb      dmns|77 dmns|110ee      ff
aa      bb      dmns|79 dmns|233ee      ff
aa      bb      dmns|79 dmns|233ee      ff

EDIT: Adding a non-one liner form of solution too now.
Code:
awk -F"\t" '{
    sub(/ /,"",$3);
    split($3,a,"|");
    q=a[2];
    v=a[3];
    sub(/[0-9]+/,"",q);
    sub(/[0-9]+/,"",v);
    if(a[2]+0>a[3]+0){
        tmp=a[2]+0;
        a[2]=a[3]+0;
        a[3]=tmp+0
};
    $3=sprintf("%s|%d%s%s|%d%s%s",a[1],a[2]+0,length(a[2]+0)>2?"":" ",q,a[3]+0,length(a[3]+0)>2?"":" ",v)
}
1
' OFS="\t"   Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 07-26-2017 at 12:43 AM.. Reason: Adding a non-one liner form of solution too now.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort by Columns

Hello, I am new in UNIX I am looking for a instrction to sort a file by columns 6,25 and 41 this is what I tried but not getting the correct result: sort -t= -k1.6,1.25,1.41 to_sort.txt > sorted.txt I used -t= just to get the whole line as one field. INVS80993596SUM994338602XX... (1 Reply)
Discussion started by: murbina
1 Replies

2. Shell Programming and Scripting

sort command - alphanumeric

I have a file I'm trying to sort such as fred1 fred2 fred10 fred11 ... when I sort I get fred1 fred10 fred11 fred2 ... using sort can any give me the syntax to sort this is dict order e.g., (4 Replies)
Discussion started by: gefa
4 Replies

3. UNIX for Dummies Questions & Answers

Sort by columns

Hello, I have a text file that looks like this and I need a bash script to: 12:48:32 PM 002* OUT 000418 01:10:34 PM 002* ONL 000418 01:49:17 PM 001* OUT 000364 01:52:09 PM 001* ONL 000364 ... The fields are: 12-hour format time, some number, state (online, offline) and another... (2 Replies)
Discussion started by: Ravendark
2 Replies

4. Shell Programming and Scripting

ksh to compare alphanumeric values from 2 files

Hi there, I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message. lspv_pre.out hdisk0 00c39eaa451144dd rootvg active hdisk1 00c39eaa45223322 ... (3 Replies)
Discussion started by: mbak
3 Replies

5. Shell Programming and Scripting

Get values from different columns from file2 when match values of file1

Hi everyone, I have file1 and file2 comma separated both. file1 is: Header1,Header2,Header3,Header4,Header5,Header6,Header7,Header8,Header9,Header10 Code7,,,,,,,,, Code5,,,,,,,,, Code3,,,,,,,,, Code9,,,,,,,,, Code2,,,,,,,,,file2... (17 Replies)
Discussion started by: cgkmal
17 Replies

6. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

Sort each row (horizontally) in AWK or any

Hello, How to sort each row in a document with numerical values and with more than one row. Example Input data (file1.txt): 4 6 8 1 7 2 12 9 6 10 6 1 14 5 7 and I want the the output to look like this(file2.txt): 1 4 6 7 8 2 6 9 10 12 1 5 6 7 14 I've tried sort -n file1.txt >... (12 Replies)
Discussion started by: joseamck
12 Replies

8. Shell Programming and Scripting

Adding columns with values dependent on existing columns

Hello I have a file as below chr1 start ref alt code1 code2 chr1 18884 C CAAAA 2 0 chr1 135419 TATACA T 2 0 chr1 332045 T TTG 0 2 chr1 453838 T TAC 2 0 chr1 567652 T TG 1 0 chr1 602541 ... (2 Replies)
Discussion started by: plumb_r
2 Replies

9. Shell Programming and Scripting

Trouble with alphanumeric Sort

I have a lot of data that need to be sorted alphanumerically. I began using sort -du and it solved almost all my problems. However, when I encountered files with data like this it began to fail: /vol/close_eng_ice_0888 /vol/open_eng_ice_0890 /vol/open_eng_ice_08923 /vol/open_eng_ice_0893... (6 Replies)
Discussion started by: newbie2010
6 Replies

10. UNIX for Dummies Questions & Answers

Want to sort a file which contains alphanumeric strings

I want to sort a file which contains alphanumeric string. bash-3.00$ cat abc mtng1so mtng2so mtng11so mtng9so mtng23so mtng7so hstg2so hstg9so hstg1so hstg11so hstg13so bash-3.00$ Want output like this, using one liner. hstg1so (1 Reply)
Discussion started by: Raza Ali
1 Replies
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 06:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy