The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Dividing single file by lines? anoc Shell Programming and Scripting 1 04-08-2008 02:08 PM
Dividing float values shash UNIX for Dummies Questions & Answers 3 01-17-2007 05:37 AM
dividing a file into two jazz High Level Programming 2 10-20-2006 08:55 AM
Scipt to do login rahulrathod Shell Programming and Scripting 1 10-05-2004 05:29 AM
dividing the screen >>> ShockTeam UNIX for Dummies Questions & Answers 4 11-06-2001 08:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2007
maco_home maco_home is offline
Registered User
  
 

Join Date: Aug 2007
Location: Luxembourg
Posts: 5
scipt dividing strings /reg expr

Hello!

I've got txt-file containing lots of data in sentences like this:


Code:
;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON;

but sometime more than on in a line like this:


Code:
;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON;;;BA;00:00:03:00;REA;RTL9;;;;BAC;:00;TIT;SEMAINE SPECIALE ~SSLOGAN~T DVD;;

Now I would like to cut this down that I have only one sentence per row:


Code:
;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON;
;;BA;00:00:03:00;REA;RTL9;;
;;BAC;:00;TIT;SEMAINE SPECIALE ~SSLOGAN~T DVD;;


(So I need a break after every 7th ";").

I tried


Code:
echo `awk '{gsub("[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}","[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}[;][.]\{0;}\012");print $0}' $fileName0 > $fileName1`

but this is obviously completly wrong...

Does anybody have an good idea how I could get the results I want?!?

Thanks very much for any kind of help!
  #2 (permalink)  
Old 08-30-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915

Code:
sed '/\([^;]*;\)\{8,\}/ s/\([^;]*;\)\{7\}/&\
/g' file

Use /usr/xpg4/bin/sed on Solaris.

Last edited by radoulov; 08-30-2007 at 06:55 AM.. Reason: correction
  #3 (permalink)  
Old 08-30-2007
maco_home maco_home is offline
Registered User
  
 

Join Date: Aug 2007
Location: Luxembourg
Posts: 5
Thanks for that, it's working very well.

But now I've got another, very similar problem...

I've got the same data:


Code:
FP7F111;;BAC;00:00:30:00;TIT;SEMAINE SPECIALE “BANDE DE SAUVAGES”;;
;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON;
;;BA;00:00:03:00;REA;RTL9;; 
;;BAC;:00;TIT;SEMAINE SPECIALE “BANDE DE SAUVAGES”;;

but now I have to remove all the linebreake (ASCII 12) so that it looks like this:


Code:
FP7F111;;BAC;00:00:30:00;TIT;SEMAINE SPECIALE “BANDE DE SAUVAGES”;;;;BA;00:00:03:00;COM;CLOQUET-LAFOLLYE;SIMON;;;BA;00:00:03:00;REA;RTL9;;;;BAC;:00;TIT;SEMAINE SPECIALE “BANDE DE SAUVAGES”;;

And I have this time absolutly no idea how to do this...

Sorry for my stupid qustions, I think I have to get some experience with reg expr's very quickly...
  #4 (permalink)  
Old 08-30-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915

Code:
 awk '$1=$1' RS= file

Use nawk or /usr/xpg4/bin/awk on Solaris.

Or, of course, with tr:


Code:
tr -d '\12'<file


Code:
tr -d '\n'<file


Last edited by radoulov; 08-30-2007 at 10:48 AM.. Reason: addition
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0