Try to quote the variable in the first echo too, that should preserve all blanks and tabs. The newline characters are lost in the outer loop, because you read the input file line by line and the terminating newline is not written to the variable by read.
You need to set IFS to "" to tell read to not break arguments on whitespace. This property is occasionally useful -- if you set IFS="," you can read in values delimited by commas instead of space-separated ones...
Note I don't set IFS globally anywhere here, since you usually expect it to break on whitespace.
So, to make your program work:
...or better yet, use a redirection to avoid a Useless Use Of Cat:
...or, even better, use string operations to get the nth character, avoiding pipes and external calls completely. This is much, much faster.
Last edited by Corona688; 02-22-2010 at 01:15 PM..
Reason: fix lots of typos
Hi,
I am trying to write a shell script to help with some digital signature work currently being undertaken where we have a file that contains a number of rows ending with ^M.
What I need to do is concatenate this using shell scripting and retain the control character. E.G.
abc^M... (5 Replies)
I want to read a file -line by line which consists of the following statements
Chr18:4000-4010
Chr20:4020-4030
Chr15:8000-8050
Pls. give a expression to read the line like this from a file
Chr18:4000-4010
the given two replies reading like that
Chr18:-10
but it is important to... (2 Replies)
In LVM I have one volume grp and it has two logical volumes A and B and both are full,so I extended my volume grp to 1GB with another hard disk and add this space to A and put my resr data .Now problem is that I get data from first hard disk only but I m unable to find data which is in second hard... (0 Replies)
How do I filter only comments and still keep Line breaks at the end of the line!?
This is one of the common tasks we all do,, How can we do this in a right way..!?
I try to ignore empty lines and commented lines using following approach.
test.sh
# \040 --> SPACE character octal... (17 Replies)
Hi Guys,
I am having a file which does not have any name when i do a ls -l
-rw-r--r-- 1 dctrdat1 dctrdata 35 Feb 09 08:04
-rw-r--r-- 1 dctrdat1 dctrdata 11961 Feb 08 06:40 DAI_data.txt
Now i want to see what is inside that file. Can you please let me know how to read... (9 Replies)
Can anyone tell me how to read a file in perl having junk characters . I have only one junk character which is repeated many times in the file. While i'm reading and printing the file , it is displaying till the 1st occurence of that junk character and rest of the file is not being read. (1 Reply)
i need to read record by record i use script
#!/bin/ksh
for i in 'cat filename'
do
echo $1
done
but i dont get expected result
i just get filename echoed on screen (4 Replies)
I am not able to receive the message on socket in the current process when its waiting for its child to exit.
code looks something like below
//in one thread of the current process
//thread 1
===============================================
int numBytes = read(sockid,buf,SIZE); //Now the... (2 Replies)
We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Hello,
I am new to shell scripting, and I am trying to create a script that reads an input like the following
firstname:lastname:age
firstname:lastname:age
firstname:lastname:age
in a text file. I have a 2 part question. First how do I open the file in a shell script. And then how can... (7 Replies)