Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


How to split a string with no delimiter


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
How to split a string with no delimiter

Hi;

I want to write a shell script that will split a string with no delimiter.
Basically the script will read a line from a file.

For example the line it read from the file contains:
99234523

These values are never the same but the length will always be 8.

How do i split this string into 4 sections of 2?

Thanks
# 3  
Code:
% fold -2 infile
99
23
45
23

# 4  
Bash, ksh93, ...
Code:
while read line
do
      a=${line:0:2}
      b=${line:2:2}
      c=${line:4:2}
      d=${line:6:2}
done

# 7  
Code:
echo "99234523" |awk 'BEGIN{FIELDWIDTHS="2 2 2 2"}{print $1 RS $2 RS $3 RS $4}'
99
23
45
23

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Split file into multiple files using delimiter
vel4ever
Hi, I have a file which has many URLs delimited by space. Now i want them to move to separate files each one holding 10 URLs per file. http://3276.e-printphoto.co.uk/guardian http://abdera.apache.org/ http://abdera.apache.org/docs/api/index.html I have used the below code to arrange...... Shell Programming and Scripting
6
Shell Programming and Scripting
split file by delimiter with csplit
yifangt
Hello, I want to split a big file into smaller ones with certain "counts". I am aware this type of job has been asked quite often, but I posted again when I came to csplit, which may be simpler to solve the problem. Input file (fasta format): >seq1 agtcagtc agtcagtc ag >seq2 agtcagtcagtc...... Shell Programming and Scripting
8
Shell Programming and Scripting
split record based on delimiter
Jairaj
Hi, My inputfile contains field separaer is ^. 12^inms^ 13^fakdks^ssk^s3 23^avsd^ 13^fakdks^ssk^a4 I wanted to print only 2 delimiter occurence i.e 12^inms^ 23^avsd^... Shell Programming and Scripting
4
Shell Programming and Scripting
renaming files using split with a delimiter
swimulator
I have a directory of files that I need to rename by splitting the first and second halves of the filenames using the delimiter "-O" and then renaming with the second half first, followed by two underscores and then the first half. For example, natfinal1995annvol1_14.pdf -O filenum-20639 will be...... Shell Programming and Scripting
2
Shell Programming and Scripting
split string with multibyte delimiter
azmathshaikh
Hi, I need to split a string, either using awk or cut or basic unix commands (no programming) , with a multibyte charectar as a delimeter. Ex: abcd-efgh-ijkl split by -efgh- to get two segments abcd & ijkl Is it possible? Thanks A.H.S... Shell Programming and Scripting
1
Shell Programming and Scripting

Featured Tech Videos