[Solved] print chars of a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] print chars of a string
# 8  
Old 11-02-2011
You can simplify that.

Code:
for ((i=0;i<${#VARIABLE};i++)) ; do 
        echo ${VARIABLE:i:1};
done

# 9  
Old 11-02-2011
thanks Smilie

---------- Post updated at 01:34 PM ---------- Previous update was at 10:11 AM ----------

instead if i want to put every chars on a different variables for each chars?
# 10  
Old 11-02-2011
Since you have BASH, you ought to have arrays:

Code:
VARIABLE="slartibartfast"
for ((i=0;i<${#VARIABLE};i++))
do 
        ARR[i]="${VARIABLE:i:1}"
        echo "ARR[i] = ${ARR[i]}"
done

Code:
$ ./myscript

ARR[0] = s
ARR[1] = l
ARR[2] = a
ARR[3] = r
ARR[4] = t
ARR[5] = i
ARR[6] = b
ARR[7] = a
ARR[8] = r
ARR[9] = t
ARR[10] = f
ARR[11] = a
ARR[12] = s
ARR[13] = t

$

# 11  
Old 11-03-2011
thanks a lot Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - print only the chars that match a given set in a string

For a given string that may contain any ASCII chars, i.e. that matches .*, find and print only the chars that are in a given subset. The string could also have numbers, uppercase, special chars such as ~!@#$%^&*(){}\", whatever a user could type in without going esoteric For simplicity take... (1 Reply)
Discussion started by: naderra
1 Replies

2. UNIX for Beginners Questions & Answers

How to print 7 chars from left of filemane?

Hi Guys Kindly help me on my predicament. I want to get the 7 chars of this filename I need to get the ALL.cmd from this filehame filename_a_ALL.cmd Thanks (10 Replies)
Discussion started by: cmarzan
10 Replies

3. Shell Programming and Scripting

Add an string at every x chars

Hi All, I have a file fo around 15k bytes which i need to insert a string " + "at every 250 bytes. I found some ideas here using perl to split into lines and tried to addapt it but the results where not satisfactory for instance i tried to change #!/usr/bin/perl $teststring =... (9 Replies)
Discussion started by: kadu
9 Replies

4. Shell Programming and Scripting

Find Special/Null/Control Chars and Print Line Numbers

Hi All, This might be a basic question... I need to write a script to find all/any Speacial/Null/Control Chars and Print Line Numbers from an input file. Output something like Null Characters in File Name at : Line Numbers Line = Print the line Control Characters in File Name at : Line... (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies

5. Shell Programming and Scripting

print all between patterns with special chars

Hi, I'm having trouble with awk print all characters between 2 patterns. I tried more then one solution found on this forum but with no success. Probably my mistakes are due to the special characters "" and "]"in the search patterns. Well, have a log file like this: logfile.txt ... (3 Replies)
Discussion started by: ginolatino
3 Replies

6. Shell Programming and Scripting

[Solved] check if chars is a capital letter and translate it

how can i check if read -n 1 LETTER; LETTER is a capital letter and after translate in minuscule. i have thought with: tr or no? (7 Replies)
Discussion started by: tafazzi87
7 Replies

7. UNIX for Advanced & Expert Users

[Solved] remove all print jobs from a print queue

Hello, Sometimes i need to clear all the jobs of a print queue and it is really annoying to cancel one by one. Is there a way to cancel all print jobs for a specific print queue with a single command instead of cancelling them one by one? My AIX system is 5.3 Thank you for your attention (2 Replies)
Discussion started by: omonoiatis9
2 Replies

8. Shell Programming and Scripting

awk to print count for chars recurrence

input: 123456 1111 124567 2222 125678 3333 234567 aaaa 456789 abcd awk logic: - read lines for recurring 1st 2 chars of the 1st field - if recurrence detected count up and print value output: 1 123456 1111 2 124567 2222 3 125678 3333 (6 Replies)
Discussion started by: ux4me
6 Replies

9. Shell Programming and Scripting

Repeatable chars in a string

I have a string I keep appending too upto certain amount of chars. Is there some sort of way for me to check the string to see if I hit my limit of repeatable characters? For example, assume I allow for 2 repeatable chars, this will be a valid string Xxh03dhJUX, so I can append the last... (3 Replies)
Discussion started by: BeefStu
3 Replies

10. Shell Programming and Scripting

Retreive string between two chars

I want to write a shell script in order to retreive some data from a log file that i have written into. The string that i want to get is the number 2849 (that is located between | | ). To explain further, this is the result i get after running "grep LOGIN filename.log" but i need to get the... (25 Replies)
Discussion started by: danland
25 Replies
Login or Register to Ask a Question