Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I process each line in a file

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I need to do a task depending on first 5 chars in each line of a file.
This script does not work (it shows each word as a line)?
for rec in `cat myfile`
do
echo $rec | cut -c1-5
done

MYFILE looks like this
ABCDEsome string of data
FRED some string of data
HARRYsome string of data
 
I dont realy understand what's your problem but to do the type of thing you want to do, an easy way to do is to use the "read" command
 
You're almost there. Try this:

Code:
for rec in `cut -c1-5 myfile`
do
echo $rec
done

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Yes,the read command will work.Thanks
 
Please re-explain. This sounds like one we can help with, but I don't really understand what you're trying to do.

My best guess (of what you're trying to do) is to try and assign the returned "echo" to a variable and then run logic based upon what's in the variable.

vfirst_five=$(echo $rec | cut -c 1-5)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top