|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Preserving whitespace in here document.
I'm trying to write a script that will preserve the white space in a here document. What I'm trying to do is write a "smart" sed script. I have a text file that needs to update a number sequentially.
For example ..indx=1 ....indx=2 ......indx=3 I want to insert an indx at line 2: ..indx=1 ....indx=# ....indx=2 ......indx=3 and have the outcome be the following ..indx=1 ....indx=2 ....indx=3 ......indx=4 Getting the numbers is easy and making the replacements is easy, but if I use a while read loop none of the white space is preserved. while read line do * do stuff * echo "$line" done < ~/tmp/myfile this would return indx=1 indx=2 indx=3 indx=4 thanks for any help |
|
#2
|
|||
|
|||
|
found out the answer
Was looking at my unix in a nutshell book table of contents. Just for kicks I went to the Shell Programming section. I saw a built-in command called line. which reads in a line of input from stdin and outputs it to stdout.
while line=`line` do echo line="$line" done < ~/tmp/testfile.txt This preserved the whitespace. ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Preserving whitespace in here document. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|