How to split a sentence

Hi,

Can anybody help me out, how can I split the sentence,

11111 12-12-2002 1000 23 22222 11-11-2011 2000 24 13131 09-02-2002

like the below format,

11111 12-12-2002 1000 23
22222 11-11-2011 2000 24
etc....

Plz help...

Thanks in advance...!!

If it's always in the same format:

bash-3.2$ cat input.txt
11111 12-12-2002 1000 23 22222 11-11-2011 2000 24
bash-3.2$ perl -pe 's/(\d{5} \d{2}-\d{2}-\d{4} \d{4} \d{2}) /$1\n/g' input.txt
11111 12-12-2002 1000 23
22222 11-11-2011 2000 24

try this-
sed 's/\([0-9]\{5\} [0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\} [0-9]\{4\} [0-9]\{2\} \)/\1\n/g' filename

11111 12-12-2002 1000 23
22222 11-11-2011 2000 24
13131 09-02-2002

cheers,
Devaraj Takhellambam

Thanks a lot friends....!!

I have one query on this..

If the sentence is like ,

111 12-12-2002 100 23 12 11-11-2011 20 2 .....

Actually the first one is the account id so the digit count will vary everytime...Apart from the date, rest all digits count will vary...so can I use the same solution which you suggested...?

Thanks in Adavance...!!

use this

sed 's/\([0-9][0-9]* [0-9]\{2\}-[0-9]\{2\}-[0-9][0-9]* [0-9][0-9]* [0-9][0-9]* \)/\1\n/g' filename

cheers,
Devaraj Takhellambam

Thanks yaaar...Thanks a lot...!!

Not without some modification, eg

perl -pe 's/(\d{,5} \d{2}-\d{2}-\d{4} \d{,4} \d{,2}) /$1\n/g'

That way the first number can be 1-5 digits, the first after the date 1-4 and the last 1 or two. Adjust according to your needs.

Thanks a lot friends...!

One more issue on this..

If I want to modify the output like the below format, how can I do it?

Employee Details

AccId Date Salary Due
111 12-12-2002 100 23
12 11-11-2011 20 2

Thanks in advance..!!

Thanks a lot friends...!

One more issue on this..

If I want to modify the output like the below format, how can I do it?

Employee Details

AccId Date Salary Due
111 12-12-2002 100 23
12 11-11-2011 20 2

Thanks in advance..!!

Try this :

sed '/\([0-9][0-9]* [0-9]\{2\}-[0-9]\{2\}-[0-9][0-
9]* [0-9][0-9]* [0-9][0-9]* \)/{i Employee Details
i AccId Date Salary Due
s//\1\n/g}' filename | awk 'NR==1{print}NR > 1{for(i=1;i<=NF;i++)printf("%-20s",$i);printf "\n"}'

cheers,
Devaraj Takhellambam

you may use perl

my $str="11111 12-12-2002 1000 23 22222 11-11-2011 2000 24 13131 09-02-2002 ";
$str=~s/(?<=[0-9]{5} [0-9]{2}-[0-9]{2}-[0-9]{4} [0-9]{4} [0-9]{2}) /\n/g;
print $str;

Hi when am using below solution,
sed 's/\([0-9][0-9]* [0-9]\{2\}-[0-9]\{2\}-[0-9][0-9]* [0-9][0-9]* [0-9][0-9]* \)/\1\n/g' filename

am getting the output like this..
111 12-12-1212 12 2009 n121 11-11-1111 11 1000

But this is not the expected result...Could you please help me out..?

Hi..

I tried with this solution..

But its showing Syntax error : '(' is expected...!!

Could you please help me out in this?

Thanks in advance..!

Assuming you want 4 fields on 1 line:

awk 'BEGIN{RS=" "}{sub("\n","")}ORS=NR%4?RS:"\n"' file

Yes...Its working fine...Thanks a lot yaaaar..!!