![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can I read a file character by character? | murtaza | Shell Programming and Scripting | 4 | 04-27-2009 05:51 AM |
| read a variable character by character, substitute characters with something else | vipervenom25 | UNIX for Dummies Questions & Answers | 2 | 06-06-2008 03:18 PM |
| Can i read a file character by character | karnan | Shell Programming and Scripting | 6 | 05-19-2008 02:22 AM |
| Need to serach if a new line character exists on the last line in a file | sunilbm78 | UNIX for Dummies Questions & Answers | 10 | 02-29-2008 02:15 PM |
| need to read 3° character from a text file | piltrafa | UNIX for Dummies Questions & Answers | 15 | 07-26-2005 10:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Read First Character of Each Line in File
I need a better way to read the first character of each line in a file and check if it equals the special character ¤. This character tells me where there is a break in the reports. The file has over 500,000 lines. Currently, this is my code -
if [[ $(echo $line|cut -c1-1) = "¤" ]]I am using Korn Shell as a scripting language. Is there a better way to do this? Thank you for your assistance. |
|
||||
|
It would work if you use the enhanced korn shell (ksh93). For something that takes this long it might be worth testing to see which is faster, assigning it to a one character variable with typeset in the standard korn shell or using the enhanced korn shell's variable substitution. Of course going from 5 hours to 45 minutes is already a pretty nice improvement.
![]() |
|
||||
|
Shell_Life's suggestion helped a lot. Processing time went from over 5 hours to 45 minutes. This was the code:
typeset -L1 mOne while read mLine do mOne=$mLine done < input_file jim mcnamara was correct that ${line:0:1} would not work. Thank you for the help. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|