Operating System - HP-UX
1830238 Members
3415 Online
109999 Solutions
New Discussion

Re: How can I keep leading blanks for input/output in a script ?

 
SOLVED
Go to solution
Luis Toro
Regular Advisor

How can I keep leading blanks for input/output in a script ?

I am trying to write a simple script that inputs a file, and based on characters 47-50, outputs each line of the file to a different file. I thought this would be a simple "while read line" loop, with a "echo $line | cut -c47-50 >> outputfile", but the problem I'm encountering is that the input lines have leading blanks, which are part of the 1-46 character count, and need to be included in the output file. Tried "print -r", but that only kept the blank spaces in the middle of the line; leading blanks were ignored.
Thanks
4 REPLIES 4
Rodney Hills
Honored Contributor
Solution

Re: How can I keep leading blanks for input/output in a script ?

To input do-

IFS=""
read -r line

This will keep leading blanks

HTH

-- Rod Hills
There be dragons...
Luis Toro
Regular Advisor

Re: How can I keep leading blanks for input/output in a script ?

that did it.
What's the IFS="" for ?
Rodney Hills
Honored Contributor

Re: How can I keep leading blanks for input/output in a script ?

IFS stands for Input Field Seperator. By default a space is used to break up a line into parameters. By setting IFS to null, then the shell will leave the data alone.

-- Rod Hills
There be dragons...
Luis Toro
Regular Advisor

Re: How can I keep leading blanks for input/output in a script ?

Thanks again.