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
script to read a line with spaces bet " " and write to a file perlamohan Shell Programming and Scripting 3 11-12-2008 04:27 AM
How to remove "New line characters" and "spaces" at a time anushree.a Shell Programming and Scripting 4 09-08-2008 06:55 PM
How to timeout the "read" command rm-r Shell Programming and Scripting 5 08-15-2008 12:22 PM
Breaking input with "read" command vino Shell Programming and Scripting 2 08-04-2005 01:10 PM
how to request a "read" or "delivered" receipt for mails plelie2 Shell Programming and Scripting 1 08-06-2002 04:26 PM

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 01-19-2009
vickylife vickylife is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 34
"read" command ignoring leading spaces

I have to read a file line by line, change it and then update the file. Problem is, when i read the file, "read" command ignores leading spaces.
The file is a script which is indented in many places for clarity. How to i make "read" command read leading spaces as well.
  #2 (permalink)  
Old 01-19-2009
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,323
Tbh, I have no idea how to preserve leading spaces when reading a file with "read". Maybe awk or sed can do the job too; can you post a glimpse of the input and desired output? Please use [ code ] and [ /code ] tags if you do so to preserve special characters, etc. and for readability, ty.
  #3 (permalink)  
Old 01-19-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
Quote:
Originally Posted by vickylife View Post
I have to read a file line by line, change it and then update the file. Problem is, when i read the file, "read" command ignores leading spaces.
The file is a script which is indented in many places for clarity. How to i make "read" command read leading spaces as well.
You should modify the current IFS in order to achieve that.
Something like:


Code:
while IFS= read -r ...

Notice that some read implementations do not support the -r option.
  #4 (permalink)  
Old 03-24-2009
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
Just would like to post a 'thank you' to radulov: After more than 1 year I found this thread and it exactly ansvering the question.
The option EFS= is works perfect (at least in my system) (the -r is not nessesary here)
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 06:03 AM.


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