Skip to main content
Fix indentation etc
Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k

how How to split a file into multiple files based on a delimeterdelimiter, and remove the delimeterdelimiter also, in unixUnix

 {1:F195}{2:O5350646}{3:{1028:076}}{4: :16R:GL :16R:ADD :19A::P//U9,1 :16S:AFO -}{5:{MAC:00}{CHK:1C}}{S:{SAC:}{COP:S}{MAN:P2}}${1:33339}{2:O53}{4: :16S:G :16R:A :19A::H0, :19A::H0, :16S:ADDINFO -}{5:{MAC:0}{CHK:4}}{S:{SAC:}{COP:S}{MAN:GP2}} {1:F195}{2:O5350646}{3:{1028:076}}{4: :16R:GL :16R:ADD :19A::P//U9,1 :16S:AFO -}{5:{MAC:00}{CHK:1C}}{S:{SAC:}{COP:S}{MAN:P2}}${1:33339}{2:O53}{4: :16S:G :16R:A :19A::H0, :19A::H0, :16S:ADDINFO -}{5:{MAC:0}{CHK:4}}{S:{SAC:}{COP:S}{MAN:GP2}} 

Now iI want to split this single file into two files based on the delimeter $delimiter $ and then remove the delimeterdelimiter also. Any help would be greatly appreciated :)

iI have used the following logic first at every occurence of $ go to a new line im able to create multiple files but those are having delimeters.:

FILE=test.dat 
  1. First at every occurrence of $ go to a new line.
  2. I'm able to create multiple files but those are having delimiters.

sed 's/$/\n&/g' $FILE > Inter_$FILE FILE=Inter_$FILECode:

FILE=test.dat sed 's/\$/\n&/g' $FILE > Inter_$FILE FILE=Inter_$FILE cat $FILE | while read line 

do sleep 1 FormattedDate=date +%Y%m%d%H%M%S Final_FILE=New_${FormattedDate}_$FILE

do  sleep 1  FormattedDate=`date +%Y%m%d%H%M%S` Final_FILE=New_${FormattedDate}_$FILE echo "line --- $line" echo "FormattedDate --- $FormattedDate" Line_Check=`echo $line | tr '$' '@' | cut -c1` ##Line_Check=`sed -e 's/\$/@/g' $line | cut -c1` echo "Line_Check --- $Line_Check" echo "Final_FILE --- $Final_FILE" if [ "$Line_Check" = "@" ] then Final_FILE=New_$FormattedDate_$FILE FILE=$Final_FILE echo "FOUND In --- $line" echo "FILE --->>> $FILE" else FILE=$Final_FILE echo "FILE --->>> $FILE" ###`echo $line | cut -c2-` >> ###cat $line` >> $FILE ###Filter_Line=`echo $line` ###echo "Filter_Line --- $Filter_Line" fi echo $line >> $FILE ###sed 's/^@//' $FILE > 3_$FILE 

done

done sed 's/^\$//' $FILE >> Final_$FILE; 

*/

how to split a file into multiple files based on a delimeter and remove the delimeter also in unix

 {1:F195}{2:O5350646}{3:{1028:076}}{4: :16R:GL :16R:ADD :19A::P//U9,1 :16S:AFO -}{5:{MAC:00}{CHK:1C}}{S:{SAC:}{COP:S}{MAN:P2}}${1:33339}{2:O53}{4: :16S:G :16R:A :19A::H0, :19A::H0, :16S:ADDINFO -}{5:{MAC:0}{CHK:4}}{S:{SAC:}{COP:S}{MAN:GP2}} 

Now i want to split this single file into two files based on the delimeter $ and then remove the delimeter also. Any help would be greatly appreciated :)

i have used the following logic first at every occurence of $ go to a new line im able to create multiple files but those are having delimeters.

FILE=test.dat 

sed 's/$/\n&/g' $FILE > Inter_$FILE FILE=Inter_$FILE

cat $FILE | while read line 

do sleep 1 FormattedDate=date +%Y%m%d%H%M%S Final_FILE=New_${FormattedDate}_$FILE

 echo "line --- $line" echo "FormattedDate --- $FormattedDate" Line_Check=`echo $line | tr '$' '@' | cut -c1` ##Line_Check=`sed -e 's/\$/@/g' $line | cut -c1` echo "Line_Check --- $Line_Check" echo "Final_FILE --- $Final_FILE" if [ "$Line_Check" = "@" ] then Final_FILE=New_$FormattedDate_$FILE FILE=$Final_FILE echo "FOUND In --- $line" echo "FILE --->>> $FILE" else FILE=$Final_FILE echo "FILE --->>> $FILE" ###`echo $line | cut -c2-` >> ###cat $line` >> $FILE ###Filter_Line=`echo $line` ###echo "Filter_Line --- $Filter_Line" fi echo $line >> $FILE ###sed 's/^@//' $FILE > 3_$FILE 

done

sed 's/^\$//' $FILE >> Final_$FILE; 

*/

How to split a file into multiple files based on a delimiter, and remove the delimiter also, in Unix

{1:F195}{2:O5350646}{3:{1028:076}}{4: :16R:GL :16R:ADD :19A::P//U9,1 :16S:AFO -}{5:{MAC:00}{CHK:1C}}{S:{SAC:}{COP:S}{MAN:P2}}${1:33339}{2:O53}{4: :16S:G :16R:A :19A::H0, :19A::H0, :16S:ADDINFO -}{5:{MAC:0}{CHK:4}}{S:{SAC:}{COP:S}{MAN:GP2}} 

Now I want to split this single file into two files based on the delimiter $ and then remove the delimiter also. Any help would be greatly appreciated :)

I have used the following logic:

  1. First at every occurrence of $ go to a new line.
  2. I'm able to create multiple files but those are having delimiters.

Code:

FILE=test.dat sed 's/\$/\n&/g' $FILE > Inter_$FILE FILE=Inter_$FILE cat $FILE | while read line do  sleep 1  FormattedDate=`date +%Y%m%d%H%M%S` Final_FILE=New_${FormattedDate}_$FILE echo "line --- $line" echo "FormattedDate --- $FormattedDate" Line_Check=`echo $line | tr '$' '@' | cut -c1` ##Line_Check=`sed -e 's/\$/@/g' $line | cut -c1` echo "Line_Check --- $Line_Check" echo "Final_FILE --- $Final_FILE" if [ "$Line_Check" = "@" ] then Final_FILE=New_$FormattedDate_$FILE FILE=$Final_FILE echo "FOUND In --- $line" echo "FILE --->>> $FILE" else FILE=$Final_FILE echo "FILE --->>> $FILE" ###`echo $line | cut -c2-` >> ###cat $line` >> $FILE ###Filter_Line=`echo $line` ###echo "Filter_Line --- $Filter_Line" fi echo $line >> $FILE ###sed 's/^@//' $FILE > 3_$FILE done sed 's/^\$//' $FILE >> Final_$FILE; 
deleted 16 characters in body; edited title
Source Link
user21926
user21926

how to Splitsplit a file into multiple files based on a delimeter and remove the delimeter also in unix

enter code hereIhave I have a file that somewhat looks like this.:

how to Split a file into multiple files based on a delimeter and remove the delimeter also in unix

enter code hereIhave a file that somewhat looks like this.

how to split a file into multiple files based on a delimeter and remove the delimeter also in unix

I have a file that somewhat looks like this:

added 1726 characters in body
Source Link
user2647888
  • 721
  • 1
  • 13
  • 24

Ihaveenter code hereIhave a file that somewhat looks like this.

Now i want to split this single file into two files based on the delimeter $ and then remove the delimeter also. Any help would be greatly appreciated :)

i have used the following logic first at every occurence of $ go to a new line im able to create multiple files but those are having delimeters.

FILE=test.dat 

sed 's/$/\n&/g' $FILE > Inter_$FILE FILE=Inter_$FILE

cat $FILE | while read line 

do sleep 1 FormattedDate=date +%Y%m%d%H%M%S Final_FILE=New_${FormattedDate}_$FILE

 echo "line --- $line" echo "FormattedDate --- $FormattedDate" Line_Check=`echo $line | tr '$' '@' | cut -c1` ##Line_Check=`sed -e 's/\$/@/g' $line | cut -c1` echo "Line_Check --- $Line_Check" echo "Final_FILE --- $Final_FILE" if [ "$Line_Check" = "@" ] then Final_FILE=New_$FormattedDate_$FILE FILE=$Final_FILE echo "FOUND In --- $line" echo "FILE --->>> $FILE" else FILE=$Final_FILE echo "FILE --->>> $FILE" ###`echo $line | cut -c2-` >> ###cat $line` >> $FILE ###Filter_Line=`echo $line` ###echo "Filter_Line --- $Filter_Line" fi echo $line >> $FILE ###sed 's/^@//' $FILE > 3_$FILE 

done

sed 's/^\$//' $FILE >> Final_$FILE; 

*/

Ihave a file that somewhat looks like this.

Now i want to split this single file into two files based on the delimeter $ and then remove the delimeter also. Any help would be greatly appreciated :)

enter code hereIhave a file that somewhat looks like this.

Now i want to split this single file into two files based on the delimeter $ and then remove the delimeter also. Any help would be greatly appreciated :)

i have used the following logic first at every occurence of $ go to a new line im able to create multiple files but those are having delimeters.

FILE=test.dat 

sed 's/$/\n&/g' $FILE > Inter_$FILE FILE=Inter_$FILE

cat $FILE | while read line 

do sleep 1 FormattedDate=date +%Y%m%d%H%M%S Final_FILE=New_${FormattedDate}_$FILE

 echo "line --- $line" echo "FormattedDate --- $FormattedDate" Line_Check=`echo $line | tr '$' '@' | cut -c1` ##Line_Check=`sed -e 's/\$/@/g' $line | cut -c1` echo "Line_Check --- $Line_Check" echo "Final_FILE --- $Final_FILE" if [ "$Line_Check" = "@" ] then Final_FILE=New_$FormattedDate_$FILE FILE=$Final_FILE echo "FOUND In --- $line" echo "FILE --->>> $FILE" else FILE=$Final_FILE echo "FILE --->>> $FILE" ###`echo $line | cut -c2-` >> ###cat $line` >> $FILE ###Filter_Line=`echo $line` ###echo "Filter_Line --- $Filter_Line" fi echo $line >> $FILE ###sed 's/^@//' $FILE > 3_$FILE 

done

sed 's/^\$//' $FILE >> Final_$FILE; 

*/

added 15 characters in body
Source Link
user21926
user21926
Loading
deleted 212 characters in body
Source Link
user2647888
  • 721
  • 1
  • 13
  • 24
Loading
Source Link
user2647888
  • 721
  • 1
  • 13
  • 24
Loading