GNU read removes blank spaces and tabs



  • 1. Help needed with font size
    Greetings, I have a script that does record count comparison of tables (in oracle) and brings out a report that shows the table name and their respective counts. The problem here is that I am not able to get all counts within a single line. It wraps the result on to next line for a single table and distorts the shape of report. Is there a way to reduce the font of words within a file or any one suggest some other way. Any help would be appreciated. TIA
  • 2. dynamic timestamps in log
    Hi guys, I've got a rather big shell script going now. A part of it contains a while loop, which can run up to five times, depending on various elements. At the top of the script I have defined three variables, that gives me a good looking and logical log, they are: log=/somefile.log info="INFO------`date +%d/%m/%y' '%T` >" warn="WARN------`date +%d/%m/%y' '%T` >" err="ERROR-----`date +%d/%m/%y' '%T` >" When I later on in the scripts append info to the log, I e.g. write: echo "$info There is a new file today, continuing\r" >>$log THE PROBLEM is, that all log entries gets the same timestamp. Even in the while loop, where the script sleeps for five minutes up to six times. How do I make a "dynamic" timestamp? I have tried to make a function, but no gain. I would still like to write my output to the log, as showed above. Thanks.
  • 3. grep: logical AND across multiple files?
    I have 8 files with a list of hostnames in each. Is there a grep one liner that will output just the hostnames common to _all_ files? a file example: hosta hostb hostc hostd cheers.
  • 4. Corrections when using Line Continuation
    How do I go back to previous lines when using line continuation. Say for example I have this command: # find / -type f | \ > gep -i 'grepped string' | \ > wc -l and before I execute the command I realize that I have a typo on the second line. How am I able to go back to that line to make the correction without having to Ctrl-C and start over again? Thanks a lot, --John

GNU read removes blank spaces and tabs

Postby Christian » Tue, 21 Nov 2006 20:59:43 GMT


With GNU bash, version 3.00.16(1)-release (i386-redhat-linux-gnu) :

# cat myfic

# while read line

Someone has an explanation ? and a solution ? ;-)



Re: GNU read removes blank spaces and tabs

Postby Eric Moors » Tue, 21 Nov 2006 21:37:43 GMT

explanation: the setting of IFS
solution: setting IFS

more detailed, IFS is by default set to space,tab,newline.
If you do not want space and newline to be used as input separators,
use a different IFS. in your case, set IFS to newline


Re: GNU read removes blank spaces and tabs

Postby Christian » Tue, 21 Nov 2006 21:55:46 GMT

53215$4561a198$c2abfc64$ XXXX@XXXXX.COM ...

Thanks ! That's it.


Re: GNU read removes blank spaces and tabs

Postby Janis » Tue, 21 Nov 2006 22:12:29 GMT

Interestingly, reading from terminal, without redirection, does not
show that behaviour...

$ echo -n "$IFS" | od -a
0000000  sp  ht  nl
$ while read line; do /bin/echo "$line" ; done | od -a
a  b    c
0000000   a  sp  sp   b  ht   c  nl

# input had a tab between b and c; removed by copy/paste posting


Re: GNU read removes blank spaces and tabs

Postby Bill Marcum » Tue, 21 Nov 2006 22:42:23 GMT

On 20 Nov 2006 05:12:29 -0800, Janis 

Leading and trailing spaces are stripped.

 $ while read line; do /bin/echo "$line" ; done | od -a
   ab c  d[space]
0000000   a   b  sp   c  sp  sp   d  nl

brain, n:
	The apparatus with which we think that we think.
		-- Ambrose Bierce, "The Devil's Dictionary"

Similar Threads:

1.GNU Bash removes blank spaces and tabs


With GNU bash, version 3.00.16(1)-release (i386-redhat-linux-gnu) :

# str="1<SP><SP>2<TAB>3"
# echo ${#str}
# 6

So far, so good. But :

# echo ${str}
# 1<SP>2<SP>3

Someone have an explanation ?


Christian command removes leading spaces - how to avoid?

How can I get each line of a file subsequently into a shell without 
loosing leading spaces?


#! /bin/bash
while read line
     echo "${line}"
done < $1


#! /bin/bash
while read line
echo "${line}"
done < $1


3.reading a file which is in user space from kernel space


Can we read a file which is in user space from kernel space.
Idea is : This file is a configuration file which contains info which
is needed by the file system. so while mounting i want to read this
file and keep it in memory.


4.Read chopping off space, and READ-ing binary data

If I have a string " doggy" and I READ it into var, var ends up as
"doggy", with the leading spaces chopped off.
How do I stop this behaviour? (Is it the IFS environment variable?)

Also, does anything special have to be done to get READ to take in
Binary data, i.e. anything in the whole 0-255 ASCII range?


The Nomad.

5.Read spaces with "read"


Given the program below:

m3vmsa3.BIpex /tmp > cat

cat foo|read
print ">>>${REPLY}<<<"

m3vmsa3.BIpex /tmp > cat foo
m3vmsa3.BIpex /tmp >

How can I read the "spaces" at the beginnig of the line?

Thanks in advance,
Jose Luis.

6. Replace tab character with spaces

7. Replace N leading tabs with 2N spaces

8. TAB instead of 8 spaces??

Return to unix


Who is online

Users browsing this forum: No registered users and 21 guest