Stack Exchange
How can i cut text in separate line in bash?
I have a text file like this:
10/22/2013  00:11:12 ioy_I2           dtgfd14_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:11:19 ioy_I2           dtgfd24_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:11:26 ioy_I2           dtgfd23_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:11:32 ioy_J2           dtgfd13_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:11:39 ioy_J2           dtgfd14_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:11:46 ioy_J2           dtgfd24_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:11:53 ioy_J2           dtgfd23_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:12:00 ioy_L2           dtgfd13_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:12:08 ioy_L2           dtgfd14_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:12:15 ioy_L2           dtgfd24_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:12:22 ioy_L2           dtgfd23_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:12:29 ioy_N2           dtgfd13_1           TC  (OFF)weqw########��kjhk6           10/22/2013  00:12:37 ioy_N2           dtgfd14_1           TC  

I must clear this file, that original file is a binary file and i want to convert it to log file same this:
10/22/2013  00:11:12 ioy_I2           dtgfd14_1           TC  (OFF)weqw  kjhk6           
10/22/2013  00:11:19 ioy_I2           dtgfd24_1           TC  (OFF)weqw  kjhk6           
10/22/2013  00:11:26 ioy_I2           dtgfd23_1           TC  (OFF)weqw  kjhk6           
10/22/2013  00:11:32 ioy_J2           dtgfd13_1           TC  (OFF)weqw  kjhk6           
10/22/2013  00:11:39 ioy_J2           dtgfd14_1           TC  (OFF)weqw  kjhk6           
10/22/2013  00:11:46 ioy_J2           dtgfd24_1           TC  (OFF)weqw  


You should be able to do it using awk by looping over the fields in the line.

i am a beginner. can you write a script for this work?

This looks like a job for sed. Simply set it to insert newline characters after a certain pattern:
sed 's|\([0-1][0-9]/[1-31]/2013\)|\n\1|g' myfile > mynewfile

How it works:

sed                    the stream editor. Learn more with "man sed"
s                      the sed command we're running in "substitute"
\( \)                  designates a capture group so we can reference it with \1 later
[0-1][0-9]/[1-31]/2013 this regex will match most dates. Modify it to suit your needs.
\n\1                   replace the previous pattern with itself prefixed by a newline
g                      continue after the first match

Notice that I've used pipes (|) instead of slashes (/) as separators, as is typical with sed. This was so that I didn't have to escape all of the slashes in the date regex pattern.
There are tons of resources for regex, but I happen to like this one.

Try this GNU sed command,
sed -ri 's/(weqw)########..(k)/\1 \2/g; s~10/22/2013~\n10/22/2013~g' file

Example:
$ sed -r 's/(weqw)########..(k)/\1 \2/g' file | sed 's~10/22/2013~\n10/22/2013~g'

10/22/2013  00:11:12 ioy_I2           dtgfd14_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:11:19 ioy_I2           dtgfd24_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:11:26 ioy_I2           dtgfd23_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:11:32 ioy_J2           dtgfd13_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:11:39 ioy_J2           dtgfd14_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:11:46 ioy_J2           dtgfd24_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:11:53 ioy_J2           dtgfd23_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:12:00 ioy_L2           dtgfd13_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:12:08 ioy_L2           dtgfd14_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:12:15 ioy_L2           dtgfd24_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:12:22 ioy_L2           dtgfd23_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:12:29 ioy_N2           dtgfd13_1           TC  (OFF)weqw kjhk6           
10/22/2013  00:12:37 ioy_N2           dtgfd14_1           TC


Use this command sed -ri 's/(weqw)########..(k)/\1 \2/g; s~10/22/2013~\n10/22/2013~g' file to save the changes made.
