The UNIX and Linux Forums  


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 10:24 PM
Can I read a file character by character? murtaza Shell Programming and Scripting 4 04-27-2009 06:51 AM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 04:18 PM
Read First Character of Each Line in File azelinsk Shell Programming and Scripting 7 07-11-2007 09:15 PM
need to read 3° character from a text file piltrafa UNIX for Dummies Questions & Answers 15 07-26-2005 11:19 AM

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

Join Date: Nov 2007
Posts: 5
Can i read a file character by character

How to read character by character using awk
  #2 (permalink)  
Old 11-21-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Either use fold -1 then pipe into awk, or loop through each character in awk, e.g....
Code:
$ cat file1
abc
$ fold -1 file1 | awk '{print $0}'
a
b
c
$ awk '{for(i=1;i<=length;i++) print substr($0, i, 1)}' file1
a
b
c

  #3 (permalink)  
Old 11-21-2007
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
What shell? Bash has the `read` builtin where you can do:

Code:
while read -n1 char; do
 #do something with the byte in $char
done <input.file

  #4 (permalink)  
Old 05-16-2008
srikanthg srikanthg is offline
Registered User
  
 

Join Date: May 2008
Posts: 16
what is -n1 heere in this syntax

could u explain what is "-n1" here in this syntax

Quote:
Originally Posted by LivinFree View Post
What shell? Bash has the `read` builtin where you can do:

Code:
while read -n1 char; do
 #do something with the byte in $char
done <input.file
  #5 (permalink)  
Old 05-16-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Quote:
read -n nchars
Read returns after reading nchars characters rather than
waiting for a complete line of input.
So -n1 means reading character by character.

Regards,
Chella
  #6 (permalink)  
Old 05-19-2008
srikanthg srikanthg is offline
Registered User
  
 

Join Date: May 2008
Posts: 16
can u explain it little bit clear

what exactly the "number 1" do in the syntax

if i give 2 what will happen .... does it read 2 chars at a time

can u explain it little bit clear

regards
srikanth
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 01:53 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