The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Nov 2009
Posts: 13
Read file line spaces

I have a script which read a file it does
while read -r line, then i echo line out
echo "$line"

Problem is the echo does not echo space and tabs at the end of each line. How do i get the end of line space as well
  #2 (permalink)  
Old 11-27-2009
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,434
Try :
Code:
while IFS= read -r line
do
   echo "[$line]"
done

Jean-Pierre.
  #3 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Oct 2009
Location: UK
Posts: 225
If you simply want to echo each line out with its tabs and spaces on the end of each line then you can use nawk: -


Code:
nawk 1 file

This will loop through the file echoing each line onto stdout without modifying them
  #4 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Nov 2009
Posts: 13
I am processing each line, so i need to need to do it another way
  #5 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Oct 2009
Location: UK
Posts: 225
I thought you must be but what are you doing with it?

If you post your code you are more likely to get a useful answer....
  #6 (permalink)  
Old 11-27-2009
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,519

Code:
# cat file
test line1
test line2

# cat file | od -c
0000000    t   e   s   t       l   i   n   e   1  \t  \n   t   e   s   t
0000020        l   i   n   e   2  \t  \n
0000030

# while IFS= read -r line;do echo $line | od -c ;done < file
0000000    t   e   s   t       l   i   n   e   1  \n
0000013
0000000    t   e   s   t       l   i   n   e   2  \n
0000013

# while IFS= read -r line;do echo "$line" | od -c ;done < file
0000000    t   e   s   t       l   i   n   e   1  \t  \n
0000014
0000000    t   e   s   t       l   i   n   e   2  \t  \n
0000014

  #7 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Oct 2009
Location: UK
Posts: 225

Code:
nawk 1 file | do your processing

Sponsored Links
Reply

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell script to read a line in gps receiver log file and append that line to new file gudivada213 Shell Programming and Scripting 3 06-24-2009 07:16 AM
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
Read variables contain spaces from text file ahmed.zaher Shell Programming and Scripting 1 10-20-2008 07:44 PM
ksh - read file with leading spaces momi Shell Programming and Scripting 2 03-17-2008 03:02 PM
How to read a line when it starts with spaces PrakashChinna Shell Programming and Scripting 3 07-03-2006 11:49 AM



All times are GMT -4. The time now is 02:37 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