![]() |
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 |
| Read a file line by line | VENC22 | UNIX for Dummies Questions & Answers | 4 | 10-30-2008 11:09 AM |
| query on how to search for a line and read 4th word from that line | jaggesh | UNIX for Dummies Questions & Answers | 4 | 07-01-2008 10:21 PM |
| read the file line by line | kittusri9 | Shell Programming and Scripting | 3 | 04-24-2008 08:26 AM |
| How to read last line of a txt file? | yongho | UNIX for Dummies Questions & Answers | 2 | 06-13-2005 01:20 PM |
| How to read from a file line by line and do stuff | spaceship | Shell Programming and Scripting | 4 | 03-17-2005 09:47 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
read a file line by line in ksh
Hi,
In ksh we use 'while read line' statement to read a file line by line. In my input file I have 5 spaces appended at the end of each line. When I use while read line statement it chops off the spaces at the end of each line Inp.txt aaaa<five spaces> bbbb<five spaces> cccc<five spaces> pgm.ksh #!/bin/ksh while read line do len=`echo "$line" | wc -c` echo $len done my_output 5 5 5 But my expected output should be, 10 10 10 Kindly help me on this. Thanks in advance, Chella. |
|
||||
|
The read command splits the line into fields separated by white space by default. You can change this by redefining the inter-field separator (IFS). Try this:
Code:
#!/bin/ksh while IFS="" read line do len=`echo "$line" | wc -c` echo $len done Last edited by Annihilannic; 08-29-2008 at 01:54 AM.. Reason: D'oh, too slow. :-) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|