Insert line break


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert line break
# 8  
Old 04-15-2010
sorry i cannot echo it
its a big file 50mb
with 300k 410530 instances

Smilie

---------- Post updated at 06:02 PM ---------- Previous update was at 06:00 PM ----------

SAC {231} ~ ] awk '{split($0,a,410530)} {for(i in a) {if(i>=2){print 410530 a[i]}}}' edit4 > edit5
awk: record `00410530428585157F04...' too long
# 9  
Old 04-15-2010
still you can run sed on it

Code:
sed 's/410530/\n&/g' inputfile > outputfile

# 10  
Old 04-15-2010
Does the file edit4 contain several lines (or) 1 large line?
-Nithin
# 11  
Old 04-18-2010
MySQL

Quote:
Originally Posted by The_Archer
sorry i cannot echo it
its a big file 50mb
with 300k 410530 instances

Smilie

---------- Post updated at 06:02 PM ---------- Previous update was at 06:00 PM ----------

SAC {231} ~ ] awk '{split($0,a,410530)} {for(i in a) {if(i>=2){print 410530 a[i]}}}' edit4 > edit5
awk: record `00410530428585157F04...' too long

I write a script hope you want to this Smilie

300K file splitted first and then processing..

I used 52 K file for test..And ok..
Code:
 
ls -lh file
-rw-r--r-- 1 root root 52K Mar 27 20:09 myfile

Code:
vim output myfile
"myfile" 1L, 52651C

Code:
 
$ ./cuttersed myfile
Please wait your file is preparing...
Your input file is prepared...
Your file splitted and processing..
Read Character Count .. 1280
Read Character Count .. 2560
Read Character Count .. 3840
Read Character Count .. 5120
Read Character Count .. 6400
Read Character Count .. 7680
Read Character Count .. 8960
Read Character Count .. 10240
Read Character Count .. 11520
Read Character Count .. 12800
Read Character Count .. 14080
Read Character Count .. 15360
.........................................
.........................................

Code:
 a part of output newfile 
 
30. editaabc file result
 
NNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
 
31. myfileaabd file result
 
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
410530JJJJJJYYYY
410530PPPPPAAAAAA
410530AAANNNNNAAA
.......................
.......................

Code:
$ cat cuttersed
 
i=2;chrc=0;chrci=0
charcount=1280
#File splitting to 1K files after than removed its..
echo "Please wait your file is preparing..."
sed -i 's/ */ /g' $1 ; sed -i 's/^.//g' $1
split --suffix-length=4 --bytes=1280 ./$1 $1
ls -1 $1* | grep -vw edit > filelist
lastfile=$( (sed '$!d' filelist) )
lastfilesize=$( (ls -l $( (sed '$!d' filelist) ) | awk {'print $5'}) )
sed -i '$d' filelist #last file remove to filelist , because of size different problem
echo "Your input file is prepared..."
echo "Your file splitted and processing.."
for files in `cat filelist`
do
    while read -n$charcount chargrp
    do
          set - $chargrp
          chargrp=""
          let chrc+=$charcount
       for word
       do
              chargrp="$chargrp$word"
        if  [ "$word" = "4" ] && [ $chrci -eq 0 ] ; then
            firstchar=$( (echo $chargrp | sed 's/.$//') )
            echo "$firtchar" >> newfile
        fi
        let chrci+=1
              if  [ "$word" = "4" ] && [ $chrci -gt 0 ] ; then
                  charnew=$( (echo $chargrp | sed 's/.$//') )
                  chartru=$( (echo $charnew | sed 's/\(.*\)\(410530[A-Z][A-Z]*$\)/\2/g') )
                  #chartru=$( (echo $charnew | sed 's/\(.*\)\(410530[A-Z][A-Z]*\)\(4$\)/\2/') )
                  echo "$chartru" >> newfile
              fi
       done
echo "Read Character Count .." $chrc
echo "" >> newfile
echo "$i. $files file result" >> newfile
echo "" >> newfile
let i+=1
    done < $files
lastchar=$( (echo $chargrp | sed 's/\(.*\)\(4.*$\)/\2/') )
echo "$lastchar" >> newfile
done
 
#Last File Processing..
chrci=0
while read -n$lastfilesize chargrp
    do
          set - $chargrp
          chargrp=""
       for word
       do
                if  [ "$word" = "4" ] && [ $chrci -eq 0 ] ; then
            firstchar=$( (echo $chargrp | sed 's/.$//') )
            echo "$firtchar" >> newfile
        fi
                let chrci+=1
                chargrp="$chargrp$word"
              if  [ "$word" = "4" ] && [ $chrci -gt 0 ]  ; then
                  charnew=$( (echo $chargrp | sed 's/.$//') )
                  chartru=$( (echo $charnew | sed 's/\(.*\)\(410530[A-Z][A-Z]*$\)/\2/g') )
                  #chartru=$( (echo $charnew | sed 's/\(.*\)\(410530[A-Z][A-Z]*\)\(4$\)/\2/') )
                  echo "$chartru" >> newfile
              fi
                 done
echo "Read Character Count .." $chrc
echo "" >> newfile
    done < $lastfile
lastchar=$( (echo $chargrp | sed 's/\(.*\)\(4.*$\)/\2/') )
echo "$lastchar" >> newfile
echo "Last file result" >> newfile
echo "" >> newfile
Removing tmp files..
rm -f filelist $1*
sed -i '1i First File Result\n' newfile
echo -e "Full Result...\n" ; cat newfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to break the line to the one above?

Hello everyone! I'm trying to make the below file1 look like file2, can anyone help? Basically I just hit backspace on every line that starts with a number. Thanks! file1: THIS#IS-IT1 4 THIS#IS-IT2 3 THIS#IS-IT3 2 THIS#IS-IT4 1 Result > file2: (4 Replies)
Discussion started by: demmel
4 Replies

2. UNIX for Dummies Questions & Answers

VI Line Break?

So I'm in a Unix class and our assignment was to go into VI and write a script to make this file tree. At the end of it, I'd like it to echo "This is the file tree you've created" then a line break, then . But I'm not sure as to who to do it. Is there a way for when I run it (./filesystem), the... (4 Replies)
Discussion started by: bbowers
4 Replies

3. UNIX for Dummies Questions & Answers

Insert a break page after certain string using SED

Hi: I have 2 files: teststring.txt and a tempfile.txt teststring file contains: s/Primary Ins./\n1/g I'm trying to search for "Primary Ins." string in tempfile. For every "Primary Ins." string that is found, a new line is inserted and put in number 1. Then, write out the newfile... (7 Replies)
Discussion started by: newbeee
7 Replies

4. Shell Programming and Scripting

Multiple line break

Hi, We had an issue with one file. Each line in the file is a record in which there will be 6 fields each separated by ; Problem is some lines are broken into pieces. like a;b; c; d; e;f instead of a;b;c;d;e;f I have filtered out all the broken lines from the original file and wrote to... (6 Replies)
Discussion started by: anjuvr
6 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. Shell Programming and Scripting

Help to remove line break

My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1.Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra... (4 Replies)
Discussion started by: cnraja
4 Replies

8. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies

9. UNIX for Dummies Questions & Answers

Insert line break in vi's command mode

Hi, When working in vi, the CTRL+j command for merging lines is very convenient. Is there an equivalent for splitting them (inserting a line break)? I often find myself pressing "i" + "return" + "esc", which I find a bit lengthy. Thanks in advance! (3 Replies)
Discussion started by: Skogsmulle
3 Replies

10. Shell Programming and Scripting

how to insert line break + string in vi (search & replace )

Hello all i have big test file that has allot of structure text something like this : <foo1 *.html> <blah action> somthing 1 somthing 2 </blah> </foo1 > now i will like to insert 2 more lines of text below the <blah action> so it will be like : <foo1... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question