Help awk/sed: putting a space after numbers:to separate number and characters.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help awk/sed: putting a space after numbers:to separate number and characters.
# 8  
Old 03-05-2013
Quote:
Code:
echo "abce1234jklm" | sed 's/[0-9]*/ & /'
Doesn't works ,
It's because you missed scrutinizer's point.

[0-9]* matches zero or more digits, so it matches the beginning of the line (containing zero digits)
[0-9][0-9]* matches one or more digits

Code:
echo "abce1234jklm" | sed 's/[0-9][0-9]*/ & /'

works as you want
This User Gave Thanks to mirni For This Post:
# 9  
Old 03-05-2013
Bipinajith ,
this is nice coding btw, and it too worked for me: Thanks a lot.

Code:
awk '{ match($0,/^[0-9]*/); print substr($0, RSTART, RLENGTH) " " substr($0, RSTART+RLENGTH) } ' file

---------- Post updated at 02:31 PM ---------- Previous update was at 02:27 PM ----------

Mirini,

Thanks for poinitng that out & explaining that earlier mentioned by Scrutinizer, and I got it fixed...wroks like charm.
Code:
echo "abce1234jklm" | sed 's/[0-9][0-9]*/ & /'
abce 1234 jklm

Thanks much...
# 10  
Old 03-05-2013
Can this be used?
Code:
sed 's/[0-9]+/ & /'

This should match minimum one digit?
[0-9]+ gives the same [0-9][0-9]*?
# 11  
Old 03-05-2013
You can with GNU sed en BSD sed -E (extended regex) option...
Code:
sed -E 's/[0-9]+/ & /' file

with regular sed an alternative to the earlier solution would be:
Code:
sed 's/[0-9]\{1,\}/ & /' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

2. Shell Programming and Scripting

How to ignore characters and print only numbers using awk?

Input: ak=70&cat15481=lot=6991901">Kaschau (1820-1840) ak=7078&cat15482=lot=70121">Principauté (1940-1993) ak=709&cat=lot15484=70183944">Arubas (4543-5043)Output: 70 15481 6991901 7078 15482 70121 709 15484 70183944 (11 Replies)
Discussion started by: sdf
11 Replies

3. Programming

putting numbers behind eachother

I want to make a program where you have to insert binary numbers like this: do { iBinary = getche(); }while(iBinary == 1 || iBinary == 0); after you get the numbers I want them to be placed behind eachother so you will get: input: 1 1 0 1 output: 1101 (7 Replies)
Discussion started by: metal005
7 Replies

4. Shell Programming and Scripting

awk/sed script to print each line to a separate named file

I have a large 3479 line .csv file, the content of which looks likes this: 1;0;177;170;Guadeloupe;x 2;127;171;179;Antigua and Barbuda;x 3;170;144;2;Umpqua;x 4;170;126;162;Coos Bay;x ... 1205;46;2;244;Unmak Island;x 1206;47;2;248;Yunaska Island;x 1207;0;2;240;north sea;x... (5 Replies)
Discussion started by: kalelovil
5 Replies

5. Shell Programming and Scripting

Insert space between characters using sed

Input: Youcaneasilydothisbyhighlightingyourcode. Putting space after three characters. You can eas ily dot his byh igh lig hti ngy our cod e. How can i do this using sed? (10 Replies)
Discussion started by: cola
10 Replies

6. Shell Programming and Scripting

Concatenating lines of separate files using awk or sed

For example: File 1: abc def ghi jkl mno pqr File 2: stu vwx yza bcd efg hij klm nop qrs I want the reult to be: abc def ghistu vwx yza jkl mno pqrbcd efg hij klm nop qrs (4 Replies)
Discussion started by: tamahomekarasu
4 Replies

7. Shell Programming and Scripting

AWK to separate numbers from logs

Hello friends, Im trying to separate a number from a log, but it seems i need help here awk '/stimated/ {print $5}' mylog.txt gives (1515.45MB). i need pure number part to use in a comparision loop so i want to separate the number part (but only 1515 not 1515.45 ) awk '/stimated/... (6 Replies)
Discussion started by: EAGL€
6 Replies

8. Shell Programming and Scripting

Separate date timestamp use awk or sed command ?

Hi, I have logfile like this : Actually the format is date format : yyyymmddHHMMSS and i want the log become this format yyyy-mm-dd HH:MM:SS for example 2009-07-19 11:46:52 Can somebody help me ? Thanks in advance (3 Replies)
Discussion started by: justbow
3 Replies

9. Shell Programming and Scripting

Putting a character between two other characters?

I need to separate Pascal style identifiers (TheyLookLikeThis) into words separated by an underscore (_). I've tried sed 's//&_&/' but this won't work (obviously). I'd love some help. (4 Replies)
Discussion started by: Ilja
4 Replies

10. Shell Programming and Scripting

how to separate every 10 characters then space then another 10 charactes

suppose u have a file P2122 AAJJSKKSKSLSKSKMSKMS P2123 AASSJMWJNSJNWHNSKSJ P2126 AHJMKNSAJNSKAKMOKALM P3533 KKKSJMAKKLLMLMSLMSPM P2122 JKKSKKMKKSKKKS--------------NSNJ P2123 NSJN---------MSKMKMKKSLLNSLL P2126 JNJSJNWKMSK-------------SKKSMK P3533 JSNSNPWLLL-SKK----SKKKSKKS so the... (2 Replies)
Discussion started by: cdfd123
2 Replies
Login or Register to Ask a Question