Read file line spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read file line spaces
# 1  
Old 11-27-2009
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  
Old 11-27-2009
Try :
Code:
while IFS= read -r line
do
   echo "[$line]"
done

Jean-Pierre.
# 3  
Old 11-27-2009
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  
Old 11-27-2009
I am processing each line, so i need to need to do it another way
# 5  
Old 11-27-2009
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  
Old 11-27-2009
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  
Old 11-27-2009
Code:
nawk 1 file | do your processing

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

4. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

5. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

6. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

7. Shell Programming and Scripting

script to read a line with spaces bet " " and write to a file

Hi, I need a command in UNIX KSH below is the description... MAPPING DESCRIPTION ="Test Mapping for the calid inputs" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1" unix ksh command to read the DESCRIPTION and write to a file Test Mapping for the calid inputs... (3 Replies)
Discussion started by: perlamohan
3 Replies

8. Shell Programming and Scripting

Read variables contain spaces from text file

Dears, I developed a shell script to read varibales from text file as the following: cat /dev/null > /rename-OUT.txt while read line do set -- `echo $line` snmpset -c dslmibs $1 sysName.0 octetstring $2 after=$(snmpget -c dslmibs $1 sysName.0 | cut -d: -f3) echo "$1,$2,$after" >>... (1 Reply)
Discussion started by: ahmed.zaher
1 Replies

9. Shell Programming and Scripting

ksh - read file with leading spaces

Hi, Could someone has any suggestions on this? When read a line from a file, I need to check the first char in the line, it could be a space or any char. But the leading spaces are removed by read. Thanks. (2 Replies)
Discussion started by: momi
2 Replies

10. Shell Programming and Scripting

How to read a line when it starts with spaces

Hi , I use read command to get the input text, When i try to get the line starting with spaces or ending with spaces it automatically truncates the spaces and displays the remaining content. Code i tried (UserInput.sh): #!/bin/bash echo -n "Enter some text > " read text echo "You... (3 Replies)
Discussion started by: PrakashChinna
3 Replies
Login or Register to Ask a Question