Keeping the number intact


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Keeping the number intact
# 8  
Old 01-06-2012
Getting confused on the difference between the following two things

Code:
sed 's/\([0-9][0-9.]*\)/ & /g'
 sed 's/\([0-9][0-9]*[.]*[0-9]*\)/ & /g'

They both seem to work in my case. I tried on the files below

Code:
n02-z30-dsr65-terr11-dc0.05-4x3smp.cmd
n02-z30-dsr65-terr12.1-dc0.05-4x3smp.cmd
n02-z30-dsr65-terr123.12-dc0.05-4x3smp.cmd

# 9  
Old 01-06-2012
When 2 solutions works, use the most simple one.

---------- Post updated at 02:25 PM ---------- Previous update was at 02:23 PM ----------

In case you get a version number like :

Code:
1.0.2.4

the first solution will still match it into 1 single matching , the second solution won't.
Code:
$ echo "1.0.2.4" | sed 's/\([0-9][0-9.]*\)/ & /g'
 1.0.2.4 
$ echo "1.0.2.4" | sed 's/\([0-9][0-9]*[.]*[0-9]*\)/ & /g'
 1.0 . 2.4

Just for a better display understanding :
Code:
$ echo "1.0.2.4" | sed 's/\([0-9][0-9.]*\)/_&_/g'
_1.0.2.4_
$ echo "1.0.2.4" | sed 's/\([0-9][0-9]*[.]*[0-9]*\)/_&_/g'
_1.0_._2.4_

So far in your file you don't have numeric string with multiple dot in it :
that is the reason why didn't you notice the difference.

Last edited by ctsgnb; 01-06-2012 at 09:33 AM..
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