The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
bash while read how to remove \n character papasj Shell Programming and Scripting 3 05-25-2009 09:24 PM
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
Read First Character of Each Line in File azelinsk Shell Programming and Scripting 7 07-11-2007 08:15 PM
need to read 3° character from a text file piltrafa UNIX for Dummies Questions & Answers 15 07-26-2005 10:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-29-2007
murtaza murtaza is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 31
Can I read a file character by character?

Hello all respected people,
Can i read a file character by character without using sed,awk and perl commands.

Thanks in advance.
  #2 (permalink)  
Old 03-29-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by murtaza
Hello all respected people,
Can i read a file character by character without using sed,awk and perl commands.
[...]
Oops, just saw "without awk ...",
so if you have fold


Code:
cnt=1; for i in $(fold -b1 inputfile);do
echo "Char # $cnt is $i"
cnt=$((cnt + 1)) 
done
With recent versions of bash:

Code:
cnt=1;while IFS= read -n1;do  
 echo "Char # $cnt is $REPLY"
 cnt=$((++cnt)) 
done<inputfile

Last edited by radoulov; 03-29-2007 at 11:43 AM..
  #3 (permalink)  
Old 03-29-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
#! /bin/ksh

typeset -L1 single
while read line
do
    while (( ${#line} > 0 ))
    do
        single="$line"
        # do what you like with $single
        echo $single
        line=${line#$single}
    done
done < input.txt
Read a line and process a character at a time.
  #4 (permalink)  
Old 03-29-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
Code:
while read -n 1 ch; do echo "$ch" ; done < file
  #5 (permalink)  
Old 04-27-2009
digitalrg's Avatar
digitalrg digitalrg is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 26
Hello All,
I need to read charters position from 55 to 50, 43 to 37, etc like these random but fixed for every line. Please help
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0