Insert\extract text with blank on unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert\extract text with blank on unix
# 1  
Old 08-14-2009
Insert\extract text with blank on unix

I need your lights.

On Unix I have a file consisting of a single line of 2 700 000 characters ...
Like that :
Code:
30004SCT TARTENPION                        00003FONTEN                                30008*E GOUDYEAR DODO   1 Street Bigggest  30004OHOHOHITSALONGLINE                    ...

And i need to insert somes ";" and cut to make end of line.
Like that :
Code:
30004;SCT TARTENPION     ;                   ;
00003;FONTEN             ;                   ;
30008;*E GOUDYEAR DODO   ;1 Street Bigggest  ;
30004;OHOHOHITSALONGLINE ;                   ;
...

I tried with "cut" but i had got troubles with blank(white spaces).

Please save meeeeee Smilie
Thks reading
# 2  
Old 08-14-2009
Quote:
Originally Posted by mangalor
...
And i need to insert somes ";" and cut to make end of line.
Like that :
Code:
30004;SCT TARTENPION     ;                   ;
00003;FONTEN             ;                   ;
30008;*E GOUDYEAR DODO   ;1 Street Bigggest  ;
30004;OHOHOHITSALONGLINE ;                   ;
...

...
One way to do it with Perl:

Code:
$
$ cat data.txt
30004SCT TARTENPION                        00003FONTEN                                30008*E GOUDYEAR DODO   1 Street Bigggest  30004OHOHOHITSALONGLINE
$
$ perl -ne 'chomp;
>           while(/(.)/g){
>             $i++; print $1; $x=$i%43;
>             if ($x == 0){print ";\n"}
>             elsif ($x==5 or $x==24){print ";"}
>           }' data.txt
30004;SCT TARTENPION     ;                   ;
00003;FONTEN             ;                   ;
30008;*E GOUDYEAR DODO   ;1 Street Bigggest  ;
30004;OHOHOHITSALONGLINE ;                   ;
$
$

tyler_durden
# 3  
Old 08-20-2009
It work's !
Yes you are my Hero !

So long to answer sorry.

Now to finish i need to delete the last 14 car of each line, but i will find that alone i think.

Thanks Tyler Durden
# 4  
Old 08-24-2009
at the end :
Code:
perl -ne 'chomp;
    while(/(.)/g){
       $i++; print $1; $x=$i%900;
       if ($x == 0){print "\n"}
       elsif ($x==5 or $x==37 or $x==42 or $x==74 or $x==79 or $x==111 or $x==116 or $x==148 or $x==153 or $x==185 or $x==187 or $x==192 or $x==224 or $x==256 or $x==288 or $x==320 or $x==333 or $x==335 or $x==340 or $x==372 or $x==404 or $x==436 or $x==468 or $x==475 or $x==480 or $x==487 or $x==503 or $x==504 or $x==509 or $x==541 or $x==573 or $x==605 or $x==637 or $x==642 or $x==655 or $x==662 or $x==694 or $x==726 or $x==758 or $x==790 or $x==795 or $x==808 or $x==815 or $x==828 or $x==830 or $x==835 or $x==840 or $x==845 or $x==847 or $x==852 or $x==861 or $x==865 or $x==870 or $x==874 or $x==878 or $x==882){print ";"}
       }' $1 | sed -e 's/[0-2]             $//' > $1_finish

This insert all ";" and insert end of line each 900 char.
After it delete(replace by nothing) last 14 char of each line and we have finish.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove blank space and insert special character

Hi Folks, I have a huge data of the below format abc #apple 1200 06/23 ghj #orange 1500 06/27 uyt #banana 2300 05/13 efg #vegetable 0700 04/16 After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies... (4 Replies)
Discussion started by: jayadanabalan
4 Replies

2. Shell Programming and Scripting

Insert a string instead of blank lines

how can i insert a string sush as "###" instead of blank lines in a file? i try this code but it doesn't work! awk 'NF<1 {$1=="###" ; print$0}' in_file > out_file (13 Replies)
Discussion started by: oreka18
13 Replies

3. Shell Programming and Scripting

sort with condition and insert blank line

Hi, I have a file with no blank line anywhere Its a conf file, The lines between and starts with "#" should be sort out with the first three characters(characters are between (a-z)). and insert a blank space in between the uniq lines. For clear understanding ,pls find the below input file... (11 Replies)
Discussion started by: anil8103
11 Replies

4. Shell Programming and Scripting

insert blank line between lines

Hello, I am trying to write a script that will count the number of characters for each line in a file and all the lines that have less than 80 characters and that are ending with a period, I want it to insert a blank line after them immediately. But, for whatever reason the condition if ]] is... (3 Replies)
Discussion started by: Pouchie1
3 Replies

5. Shell Programming and Scripting

Insert blank line if grep not found

Hi all, I've googling around forum regarding my prob, the nearest would same as thread tittled Insert blank line if grep not found, but she/he did not mention the solution, so I would like to request your help I've this task, to search in file2 based on pattern in file1 and output it to... (4 Replies)
Discussion started by: masterpiece
4 Replies

6. Shell Programming and Scripting

Insert blank line in a file

I have a file with data as below : Heading 1 ------------- Heading 1 data1 Heading 1 data2 Heading 1 data3 Heading 1 data4 Heading 2 ------------- Heading 2 data1 Heading 2 data2 Heading 2 data3 Heading 2 data4 Heading 3 ------------- Heading 3 data1 Heading 3 data2 Heading 3... (2 Replies)
Discussion started by: yoursdivu
2 Replies

7. UNIX for Dummies Questions & Answers

Removing blank spaces from text files in UNIX

Hello, I am an super newbie, so forgive my sheer ignorance. I have a series of text files formatted as follows (just showing the header and first few lines): mean_geo mean_raw lat lon 0.000 0 -70.616 163.021 0.000 0 -70.620 163.073 0.000 ... (8 Replies)
Discussion started by: vtoniolo
8 Replies

8. Shell Programming and Scripting

compare three files and insert a blank line at each mismatch

i need to compare three files in unix a.txt b.txt c.txt 1 2 1 2 5 3 4 6 5 5 6 6 i need to insert a blank line in the file if i don't find a match and put the items at the same column if found a match The items in the files... (4 Replies)
Discussion started by: mad_man12
4 Replies

9. Shell Programming and Scripting

insert text and add blank line

I need your help, I want to add a text every 2nd line and also a blank line after 3 line (In the output 2nd line is "changetype: modify" and every 4th line is blank line) Input file format dn: abc orclsourceobjectdn: abcd dn: bcd orclsourceobjectdn: bcda dn: cba orclsourceobjectdn:... (7 Replies)
Discussion started by: athidhi
7 Replies

10. Shell Programming and Scripting

Insert blank line if grep not found

Hello everyone... please help if you can -- I'm stumped. Making this work will save me hours of manual labor: I need to search file2 for pattern in file1. If pattern found append file2 line to file3. If pattern not found append a blank line to file3. file1 contents example: 123 456 789... (6 Replies)
Discussion started by: michieka
6 Replies
Login or Register to Ask a Question