Keeping the number intact


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Keeping the number intact
# 1  
Old 01-06-2012
Keeping the number intact

Currently I have the following to separate the numeric values. However the decimal point get separated.

Code:
ls -lrt *smp*.cmd | awk '{print $NF}' | sed 's/^.*\///' | sed 's/\([0-9][0-9]*\)/ & /g'

As an example on the files
Code:
n02-z30-dsr65-terr0.50-dc0.05-4x3smp.cmd
n02-z30-dsr65-terr0.50-dc0.01-8x6smp.cmd
n02-z30-dsr65-terr0.50-dc0.006-8x6smp.cmd
n02-z30-dsr65-terr0.50-dc0.008-8x6smp.cmd

I am getting

Code:
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 05 - 4 x 3 smp.cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 01 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 006 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 008 - 8 x 6 smp.cmd

I would like to have something like the following instead

Code:
 n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.05 - 4 x 3 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.01 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.006 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.008 - 8 x 6 smp.cmd

In this way the numbers are separated without detaching the decimal point.
# 2  
Old 01-06-2012
Try:
Code:
ls -lrt *smp*.cmd | awk '{print $NF}' | sed 's/^.*\///' | sed 's/\([0-9][0-9.]*\)/ & /g'

# 3  
Old 01-06-2012
@kristinu

Code:
sed 's/ \. /./' yourfile

Do you still have sorting issue with that list ?
# 4  
Old 01-06-2012
Code:
$ echo 'n02-z30-dsr65-terr0.50-dc0.05-4x3smp.cmd' | sed 's/\([0-9][0-9]*[.]*[0-9]*\)/ & /g'
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.05 - 4 x 3 smp.cmd

# 5  
Old 01-06-2012
Hi kristinu,

You may need the GNU version of 'sed' to use next command:
Code:
$ ... | sed 's/\([0-9]\+\(\.[0-9]\+\)\?\)/ \1 /g'
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.05 - 4 x 3 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.01 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.006 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.008 - 8 x 6 smp.cmd

Regards,
Birei
# 6  
Old 01-06-2012
Quote:
Originally Posted by ctsgnb
@kristinu

Code:
sed 's/ \. /./' yourfile

Do you still have sorting issue with that list ?
Not much now, just that having the complete number will make my life much easier, especially if I got to do a sort after.
# 7  
Old 01-06-2012
add the dot in the list then :
Code:
... | sed 's/\([0-9][0-9.]*\)/ & /g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to control grep output intact for each matching line?

I have multiple (~80) files (some can be as big as 30GB of >1 billion of lines!) to grep on a pattern, and piped the match to a single file. I have a 96-core machine so that each grep job was sent to the background to speed up the search: file1.tab chr1A_part1 123241847 123241848... (6 Replies)
Discussion started by: yifangt
6 Replies

2. Shell Programming and Scripting

Printing the output of a gzip command intact

how can i get the printf command or the echo command to print the data that are inbetween the first and the last quotes? #!/bin/sh printf '%s\n' "^_<8b>^H^@U<8c>MX^@^Cí=ÙzÚH<97>×ð^Teìn<8c>Ób_<9d><9f>dXd<9b>^N^F7<82>8qâÎ'^K^Y^T<83>D<90>°M^Lý^Hó^Fs5w3ß|s5/ÐýbS%©<84>^DBH... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Remove duplicates by keeping the order intact

Hello friends, I have a file with duplicate lines. I could eliminate duplicate lines by running sort <file> |uniq >uniq_file and it works fine BUT it changes the order of the entries as it we did "sort". I need to remove duplicates and also need to keep the order/sequence of entries. I... (1 Reply)
Discussion started by: magnus29
1 Replies

4. Shell Programming and Scripting

Grab data between 2 keywords any do an array operation and write the file intact

Hi Unix Gurus, I need to grep for a block that is between a start and end keyword and then in between I need to find and replace a keyword. for eg: I need to search between Test = 000; and Test = 000; and find K9 and replace with M9 INPUT FILE Define { Replace = K9; Test =... (6 Replies)
Discussion started by: naveen@
6 Replies

5. Shell Programming and Scripting

Remove last few characters in a file but keeping Header and trailer intact

Hi All, I am trying write a simple command using AWK and SED to this but without any success. Here is what I am using: head -1 test1.txt>test2.txt|sed '1d;$d' test1.txt|awk '{print substr($0,0,(length($0)-2))}' >>test2.txt|tail -1 test1.txt>>test2.txt Input: Header 1234567 abcdefgh... (2 Replies)
Discussion started by: nvuradi
2 Replies

6. Shell Programming and Scripting

Need to Zip files three years old or longer but leave folder structure intact

Hi all, Hello everyone, my first post here :). I tried to search the forum but I didn't find exactly what I was looking for... I need to zip/tar files across entire filesystem which are more 3+ years old but leave folder structure intact. If the script locates tar/zip files they are more... (1 Reply)
Discussion started by: sashruby
1 Replies

7. UNIX for Dummies Questions & Answers

sort by keeping the headings intact?

Hi all, I have a file with 3 columns separated by space. Each column has a heading. I want to sort according to the values in the 2nd column (ascending order). Ex. Name rank direction goory 0.05 --+ laby 0.0006 --- namy 0.31 -+- ....etc. Output should be Name rank direction laby... (3 Replies)
Discussion started by: Unilearn
3 Replies

8. Shell Programming and Scripting

Help with file editing while keeping file format intact

Hi, I am having a file which is fix length and comma seperated. And I want to replace values for one column. I am reading file line by line in variable $LINE and then replacing the string. Problem is after changing value and writing new file temp5.txt, formating of original file is getting... (8 Replies)
Discussion started by: Mruda
8 Replies

9. Shell Programming and Scripting

Removing sections and leaving separators intact

I have an awk script like below function abs(val) { return val > 0 ? val : -val } # 1. Main input loop, executed for each line of input BEGIN { RS = ORS = ">" } { if ( NF > 2 ) { if ( abs( $1 - $(NF-2) ) < 40 ) { print } } } The input file is something like... (2 Replies)
Discussion started by: kristinu
2 Replies

10. Shell Programming and Scripting

Grab terms leaving spacings intact

Hi All, I have an input below. I would want to print the 2nd to 5th term leaving the same number of spaces in between each term to be intact. Here in the example, there are 4 spacings between term " ABC " and " 111 ", and i tried the below awk codes but they don;t work. Can anybody give me... (3 Replies)
Discussion started by: Raynon
3 Replies
Login or Register to Ask a Question