scipt dividing strings /reg expr


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scipt dividing strings /reg expr
# 1  
Old 08-30-2007
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... Smilie

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

Thanks very much for any kind of help!
# 2  
Old 08-30-2007
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  
Old 08-30-2007
Thanks for that, it's working very well.

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

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  
Old 08-30-2007
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

expr help - managing strings

Hi guys, I need to use regular expressions in linux and I'm not quite experience in that field, maybe someone could give me some help with it. Basically, I need to take a text like this. A234321=http://www.google..... a normal URL But, I need to take the string starting at... (0 Replies)
Discussion started by: ocramas
0 Replies

2. Programming

How to prevent incorrect string using reg expr in Java?

Hi All, I need your input on how to mask out / ignore a string that does not match a working regular expression (continually refining) pattern in Java. Below is the code snippet which is picking up all the lines with the correct regular expression string except one known so far: public... (0 Replies)
Discussion started by: gjackson123
0 Replies

3. Shell Programming and Scripting

test expr VS [ expr ]

What is the difference between test expr VS . For example : if test 5 -eq 6 echo "Wrong" and if echo "Wrong" bot will give the same output as Wrong. Now, what is the difference between these two? though they are producing the same result why we need two? Any answer will be... (2 Replies)
Discussion started by: ashok.g
2 Replies

4. Shell Programming and Scripting

perl: reg.expr: combine starting and ending removal in one exprecion

Hello, I am new in perl and in regular exprecion; so I am looking for help (or an experienced advise.) The target is a triming spaces from a string: i.e., remove spases from begining and from end of a string. One of main point of a searched solution is performance: for current task it is... (2 Replies)
Discussion started by: alex_5161
2 Replies

5. Shell Programming and Scripting

HowTo: reg expr doing grep "timestamp>$DesiredTime" logfile ?

I know I asked a similar question but I want to know if there is a regular expression existing that with a korn shell cmd, finds any timestamp data records in a file where it is greater then a timestamp in a shell variable ? something like : grep all records where it has a timestamp >... (5 Replies)
Discussion started by: Browser_ice
5 Replies

6. Shell Programming and Scripting

print column that match reg expr

Hi all, I want to cut a column which match the regular expression "beta", if I don't know the column number? cat test alpha;beta;gamma 11;22;33 44;55;66 77;88;99 should be command .... beta 22 55 (6 Replies)
Discussion started by: research3
6 Replies

7. Shell Programming and Scripting

PERL: Simple reg expr validate 6 digits number

Hi there! I'm trying to validate a simple 6 digits number with reg expr. I ONLY want 6 digits so when i type 7 digits the script should no validate the number. I've write this code: #!/usr/bin/perl while(<STDIN>){ if($_=~/\d{6}/){ print "Bingo!\n"; ... (2 Replies)
Discussion started by: BufferExploder
2 Replies

8. Shell Programming and Scripting

var substitution in a reg expr ?

In a shell script, how I can achieve substitution of shell script var to a regular expression, as shown below. var=`head -1 file1` awk '$0!~/$var/ {print $0}' file1 > file2 In the case above $var value literally considered for non-exists criteria. (3 Replies)
Discussion started by: videsh77
3 Replies

9. Shell Programming and Scripting

Text replace by position instead of reg expr.

Can we replace the contents the of the rows of file, from one position to another position by mentioning, some start position & the width? (4 Replies)
Discussion started by: videsh77
4 Replies

10. Shell Programming and Scripting

Scipt to do login

I want a script which will run in the background. $ sh s.sh& 523 Then this script should provide input to the Login command. $ login login: i.e instead of the user typing in the username and password, the script running in the background should provide the username and password assuming... (1 Reply)
Discussion started by: rahulrathod
1 Replies
Login or Register to Ask a Question