Sort a las file keep the header as it is


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sort a las file keep the header as it is
# 8  
Old 09-15-2015
Yes, my mistake. Of course sorting must start after the ~Ascii!
# 9  
Old 09-16-2015
Thanakd Don

Thanks a lot Don
It worked with the creating new file.
_________________________________________________
Code:
for file in *.las
do      sed -n '1,/~Ascii/p;/~Ascii/q' "$file" > "$file.new"
        sed '1,/~Ascii/d' "$file" | sort -k1,1n >> "$file.new"
done

__________________________________________________

I have additional question to the las file.
Now it is sorted, there is a small issue with the file.
The first column is depth .

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204     abb 350 2 name
11500     abc 400 1 name2
11632     .... ..... .  .........
11632   .....
11900

and so on

Once the file is sorted I am not able to load it to the software I am using .
The reason is that there is a repetition of depth in between (11204 ,11204)
What I want to do is if it find a repetition to add to one of the depth ".1"
the file will look something as following :

Code:
11200.45  abc 400 1 name2
11204      abc 230 1 name
11204.1    abb 350 2 name
11500      abc 400 1 name2
11632       .... ..... .  .........
11632.1    .....
11900

and so on

Thanks and regards

Last edited by Don Cragun; 09-16-2015 at 02:54 AM.. Reason: Add CODE tags.
# 10  
Old 09-16-2015
How many lines could appear in your input with the same 1st column value. (I assume we need to do something like 11200.01, 11200.02, ... 11200.45 rather than 11200.1, 11200.2, ... 11200.45 so the program reading your data won't see 11200.1 and 11200.10 as having the same numeric value??? So, the question is how many digits do you need to put after the decimal point to make the number of digits after the decimal constant for the lines that have the same base first field value?
# 11  
Old 09-16-2015
repetition

Thanks again Don

The repetition happens once for each and some times twice.
Two digits after the decimal would do.

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  .........
11632   .....
11632   ...
11900
12000

regards

Last edited by Don Cragun; 09-16-2015 at 07:04 AM.. Reason: Add CODE tags again.
# 12  
Old 09-16-2015
Quote:
Originally Posted by tk2000
Thanks again Don

The repetition happens once for each and some times twice.
Two digits after the decimal would do.

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  .........
11632   .....
11632   ...
11900
12000

regards
I don't get it... If a number can be repeated in the input no more than three times, why isn't one digit enough?

If a number can be repeated in the input no more than three times, where did 11200.45 come from? Is the above supposed to be input or output? If it is input why are there any decimal points in the 1st field in the input? If it is output, why aren't there decimal points after two of the lines that start with 11632?

Are you now saying that the input could have three lines with 11200.45 in the first column and you want the output to be 11200.45, 11200.45.1, and 11200.45.2? Do you want the output sorted numerically or alphanumerically? (A numeric sort might not work if the strings you're sorting contain more than one decimal point.
# 13  
Old 09-16-2015
decimal

Hi
It is enough with one digit decimal. but in some of the files , there is two digit decimal for e.g. in one of the file the first is 11200.45 then the others in the first column is no decimal or in between there is a decimal.. if the file is as following :
the "." is for decimal ...

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  .........
11632   .....
11632   ...
11900
12000

The result I am looking for is :
Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204.1     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  .........
11632.1   .....
11632.2   ...
11900
12000

or

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204.01     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632.01     .... ..... .  .........
11632 .02  .....
11632   ...
11900
12000


regards
Moderator's Comments:
Mod Comment If you continue to refuse to show sample input, sample output, and sample code segments in CODE tags, you will eventually be banned from using this site.

Please review the forum rules you agreed to when you joined this site and format your posts properly instead of depending on forum moderators and administrators to clean up your posts for you!

Last edited by Don Cragun; 09-16-2015 at 10:28 PM.. Reason: ADD CODE tags again!
# 14  
Old 09-16-2015
Quote:
Originally Posted by tk2000
Hi
It is enough with one digit decimal. but in some of the files , there is two digit decimal for e.g. in one of the file the first is 11200.45 then the others in the first column is no decimal or in between there is a decimal.. if the file is as following :
the "." is for decimal ...

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  .........
11632   .....
11632   ...
11900
12000

The result I am looking for is :
Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204.1     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  .........
11632.1   .....
11632.2   ...
11900
12000

or

Code:
11200.45 abc 400 1 name2
11204     abc 230 1 name
11204.01     abb 350 2 name
11500     abc 400 1 name2
11600     ...  .............
11632.01     .... ..... .  .........
11632 .02  .....
11632   ...
11900
12000


regards
Moderator's Comments:
Mod Comment If you continue to refuse to show sample input, sample output, and sample code segments in CODE tags, you will eventually be banned from using this site.

Please review the forum rules you agreed to when you joined this site and format your posts properly instead of depending on forum moderators and administrators to clean up your posts for you!
I do not yet understand how the input you are processing is supposed to be converted into the output you want. Explain what output should be produced by showing us (in CODE tags) the exact output that should be produced for the following input AND by stating the rules (in English) that explain the logic your script is supposed to use to determine why that is the output it should produced from that given input:
Code:
11200.45 abc 400 1 name2 original
11200.45 abc 400 1 name2 update 1
11200.45 abc 400 1 name2 update 2
11204     abc 230 1 name
11204     abc 230 1 name
11204     abc 230 1 name
11204.01     abc 230 1 name
11204.01     abc 230 1 name
11204.01     abc 230 1 name
11204.02     abc 230 1 name
11204.02     abc 230 1 name
11204.02     abc 230 1 name
11204.1     abb 350 2 name
11204.1     abb 350 2 name
11204.10     abc 230 1 name
11204.10     abc 230 1 name
11500     abc 400 1 name2
11600     ...  .............
11632     .... ..... .  ......... original
11632     .... ..... .  ......... update 1
11632     .... ..... .  ......... update 2
11632.01     .... ..... .  ......... original
11632.01    .... ..... .  ......... update 1
11632.01     .... ..... .  ......... update 2
11632 02    .... ..... .  ......... original
11632.02     .... ..... .  ......... update 1
11632.02     .... ..... .  ......... update 2
11632.1   ..... original
11632.1   ..... update 1
11632.11 .... original
11632.11 .... update 1
11632.2   ... original
11900
12000

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort without Header and Trailer

Hi , My UNIX system is SUN Solaris. I am trying to do a simple thing as described below. I have a PIPE delimited file that has header and trailer. So the file is something like below: Test1.txt looks like something below: field_data1|field_data2|and some more data --Header ... (5 Replies)
Discussion started by: Saanvi1
5 Replies

2. Shell Programming and Scripting

Sort and Split file with header and custom name

Hi, I am using SUN SOLARIS (SunOS sun4v sparc SUNW, T5240). I have a huge data file with header and trailer. This file gets used into an ETL process. ETL skips the header record (which is the first record of the file) and loads the rest of the record. The file can be delimited (comma,... (5 Replies)
Discussion started by: Saanvi1
5 Replies

3. UNIX for Dummies Questions & Answers

Sort a las file keep the header as it is

I have several las files with a header and each file start Version and text and before the data starts end up with ~Ascii, then the numbers starts: ------------------------------------------------------------------------- Code: ~Version .....text.... ~Ascii 2 abc 230 1 name 1 abc ... (1 Reply)
Discussion started by: tk2000
1 Replies

4. UNIX for Dummies Questions & Answers

How can i sort a .txt file without loosing the header information?

Hi, I'm trying to sort 2 different .txt tab delimited files with the command line: sort -k 1b,1 inputfile > outputfile But doing that i'm also sorting the header (that ends at the end of my file). How can i sort a .txt file without sorting the header but conserving the header in the... (3 Replies)
Discussion started by: alisrpp
3 Replies

5. UNIX for Dummies Questions & Answers

Sort a tab file with header.

How to sort a tab delimited file first on col1 and then on col2. Also I need to keep the header intact. file.txt val1 val2 val3 val4 a b c d m n o p e f g h i j k l ... (3 Replies)
Discussion started by: mary271
3 Replies

6. Shell Programming and Scripting

sort a report file having header and footer

I am having report file with header and footer . The details in between header and footer are separated by a pipe charater. I want to sort the file by considering multiple columns in between header and footer. pls help (4 Replies)
Discussion started by: suryanarayana
4 Replies

7. Shell Programming and Scripting

Ignore Header and Footer and Sort the data in fixed width file

Hi Experts, I want to Sort the data in fixed width file where i have Header and Footer also in file. I m using below commad to do the sort based on field satarting from 15 position to 17 position , but it is not ignoring the Header and Footer of the file while sorting. In the output i am... (5 Replies)
Discussion started by: sasikari
5 Replies

8. Shell Programming and Scripting

Simple sort with header

Hi, Please help with this problem. Somehow does not work for me. test.txt CHR SNP BP A1 C_A C_U A2 CHISQ P OR 19 rs10401969 19268718 C 222 890 T 0.03462 0.8524 0.9857 1 rs10873889 ... (4 Replies)
Discussion started by: genehunter
4 Replies

9. UNIX for Dummies Questions & Answers

Sort and uniq lines of a file while keeping a header line

So, I have a file that has some duplicate lines. The file has a header line that I would like to keep at the top. I could do this by extracting the header from the file, 'sort -u' the remaining lines, and recombine them. But they are quite big, so if there is a way to do it with a single... (1 Reply)
Discussion started by: Digby
1 Replies

10. UNIX for Dummies Questions & Answers

Add a header to a sort file instruction

Hello, I have a header which I have to add to a sorted file, however if I use cat header sortedfile > newfile, the operation takes 2 minutes as the sorted file is over 400mb. I have noticed that when I sort the 400mb unsorted file, this only takes 14 seconds to create the output. As... (2 Replies)
Discussion started by: clarcombe
2 Replies
Login or Register to Ask a Question