LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-17-2007, 06:47 AM   #1
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Rep: Reputation: 30
truncate help


hi all
i have a text like this
Quote:
AAAAA GGGGGG 25OC200 - - 5389.80 5203.10 5673.15 5255.00 89085 234115.83 5143.90 AAAAA GGGGGG 29NO2007 - - 5389.00 5211.00 5674.00 5269.95 5265 13869.14 5143.90 BBBBBB GGGGGG 25OC200 CE 5600.00 74.00 15.00 168.60 34.05 810 2281.01 5143.90 AAAAA GGGGGG 27DE200 - - 5410.00 5125.00 5664.05 5265.00 694 1828.64 5143.90
i wanna output like this
Quote:
AAAAA GGGGGG 25OC200 - - 5389.80 5203.10 5673.15 5255.00 89085 234115.83 5143.90
AAAAA GGGGGG 29NO2007 - - 5389.00 5211.00 5674.00 5269.95 5265 13869.14 5143.90
BBBBBB GGGGGG 25OC200 CE 5600.00 74.00 15.00 168.60 34.05 810 2281.01 5143.90
AAAAA GGGGGG 27DE200 - - 5410.00 5125.00 5664.05 5265.00 694 1828.64 5143.90
line by line

is there any script to do like this

please help me

thank you in advance
 
Old 10-17-2007, 07:07 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
there are plenty of ways to do this, but you need to define exactly what is differentiating one line from another. two numbers followed by a space and then 5 letters? a quick test gives a sed regex like this...

sed 's/\.\([0-9]*\)\ \([A-Z]\)/\.\1\n\2/g'


for example.
 
Old 10-17-2007, 07:15 AM   #3
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 35
Code:
 awk --re-interval '$0=$0RT' RS=" ([[:digit:].]* ){7,8}" filename
 
Old 10-17-2007, 07:17 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
It would work better using a code block in your example. Using a quote block will squeeze spaces and insert newline characters.
 
Old 10-18-2007, 07:03 AM   #5
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Original Poster
Rep: Reputation: 30
hi all
i have a text file like this
Quote:
AAAAA GGGGGG 25OC200 - - 5389.80 5203.10
5673.15 5255.00 89085 234115.83 5143.9
AAAAA GGGGGG 29NO2007 - - 5389.00 5211.00 5674.00 5269.95 5265
13869.14 5143.90
BBBBBB GGGGGG 25OC200 CE 5600.00 74.00 15.00
168.60 34.05 810 2281.01 5143.90
AAAAA GGGGGG 27DE200 - - 5410.00 5125.00 5664.05 5265.00 694 1828.64
5143.90
i wanna output like this
Quote:
AAAAA GGGGGG 25OC200 - - 5389.80 5203.10 5673.15 5255.00 89085 234115.83 5143.90
AAAAA GGGGGG 29NO2007 - - 5389.00 5211.00 5674.00 5269.95 5265 13869.14 5143.90
BBBBBB GGGGGG 25OC200 CE 5600.00 74.00 15.00 168.60 34.05 810 2281.01 5143.90
AAAAA GGGGGG 27DE200 - - 5410.00 5125.00 5664.05 5265.00 694 1828.64 5143.90
please help me

thank you in advance
 
Old 10-18-2007, 08:17 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
you've already given us example text... you;'re just ignoring all the useful information you've already been given and starting again? I thought there was a reason i shouldn't have answered....
 
Old 10-18-2007, 08:24 AM   #7
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by acid_kewpie View Post
you've already given us example text... you;'re just ignoring all the useful information you've already been given and starting again? I thought there was a reason i shouldn't have answered....
sorry
if that command used in c program with popen the output printing like that..
so that i asked the querry again

please help me

thank you in advance
 
Old 10-18-2007, 05:51 PM   #8
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
I didn't realize that the data was actually all on one line until just after I posted my response.

I like the posted solution. It took me a while to see how it worked because I was thinking the regex was like [[:digit:].]{7,8} instead.
Code:
awk --re-interval '$0=$0RT' RS=" ([[:digit:].]* ){7,8}" filename
 
Old 10-18-2007, 09:24 PM   #9
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
This does it based on there always being 12 fields (both your examples seem to indicate this).
Code:
$ cat file
AAAAA GGGGGG 25OC200 - - 5389.80 5203.10
5673.15 5255.00 89085 234115.83 5143.9
AAAAA GGGGGG 29NO2007 - - 5389.00 5211.00 5674.00 5269.95 5265
13869.14 5143.90
BBBBBB GGGGGG 25OC200 CE 5600.00 74.00 15.00
168.60 34.05 810 2281.01 5143.90
AAAAA GGGGGG 27DE200 - - 5410.00 5125.00 5664.05 5265.00 694 1828.64
5143.90
Code:
$ perl -0e '$_=<>;s/\n/ /g;for(split){$i++;($i%12 ? print "$_ " : print "$_\n")}' file
AAAAA GGGGGG 25OC200 - - 5389.80 5203.10 5673.15 5255.00 89085 234115.83 5143.9
AAAAA GGGGGG 29NO2007 - - 5389.00 5211.00 5674.00 5269.95 5265 13869.14 5143.90
BBBBBB GGGGGG 25OC200 CE 5600.00 74.00 15.00 168.60 34.05 810 2281.01 5143.90
AAAAA GGGGGG 27DE200 - - 5410.00 5125.00 5664.05 5265.00 694 1828.64 5143.90

Last edited by angrybanana; 10-18-2007 at 09:43 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to truncate munna_dude Programming 5 07-25-2007 11:56 PM
how can i truncate this munna_dude Linux - Networking 1 06-15-2007 11:42 PM
how can i truncate this munna_dude Programming 24 04-12-2007 03:44 AM
how to use truncate sureshbabu Linux - Newbie 1 10-29-2003 04:22 AM
truncate command butthead Linux - General 1 05-14-2002 03:40 AM


All times are GMT -5. The time now is 12:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration