Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

moving through a string

Original Message
Name: numassa
Date: November 21, 2006 at 09:01:44 Pacific
Subject: moving through a string
OS: red hat
CPU/Ram: 2/1
Model/Manufacturer: sony
Comment:
Hi,
how do you move through a mixed string of characters and perform an action on each one? e.g if you do $ ls -l file ..then the result is one row with the permission string at the start ( a mix of letters and '-'s ) how would I move through each character of the permission string and assign it a new value and put in a new file. I have spent a worrying amount of time on this problem and this is the closest I can get...

count=1
ls -l file | while read str
do
until [ $count -eq 10 ]
echo "$str" £count >> newfile
count=`expr $count + 1`
done
done

and this is just my attempt to put the position number after each of the first ten characters!! and it doesnt work.

Any help would be greatly appreciated.



Report Offensive Message For Removal


Response Number 1
Name: nails
Date: November 21, 2006 at 10:07:50 Pacific
Subject: moving through a string
Reply: (edit)
IMO, the best way to cycle thru a string is to use the unix cut command:

#!/bin/sh

count=0
ls -l file | while read str
do
until [ $count -eq 10 ]
do
count=`expr $count + 1`
char=`echo $str|cut -b"$count"`
echo $char
done
done


Report Offensive Follow Up For Removal

Response Number 2
Name: numassa
Date: November 21, 2006 at 13:15:40 Pacific
Subject: moving through a string
Reply: (edit)
That works perfectly - thanks very much for you help.

Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: moving through a string

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC