Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make 'print' or 'echo' keep leading blanks?

Status
Not open for further replies.

Camogli

Programmer
Jul 10, 2001
2
US
Hi,

I simply want to read each line in a file, and then spit it out faithfully to STDOUT. The problem is when I use 'print' or 'echo' to spit out the line, the leading blanks are stripped, i.e. original " hahaha", after 'print' or 'echo', it becomes "hahaha". I need the lines to be intact. How do I do it??!!

Here is the snip of my script:

cat $filename | while read line ;do
print "$line"
done

Any clue is greatly appreciated.

Shalese
 
Why not just do

cat $filename > newfile.txt

then print text file...if you need to get only specific
lines you can

cat $filename > grep "string" > newfile.txt

hope this helps
 
I left out some details. ;-) I need to insert a block of text at a very specific place in that file.
Therefore, I need to read each line in order to find out if it's time to insert the block. I can't just use 'cat'.
Also, the "signaling" line does not appear in a fixed line number or anything.

Of course, if there is any good way to insert, be happy to hear about it too. I tried 'sed'. The problem is my file contains double quotes and all kinds of other goodies, it always causes "command garbled". :-(

Shalese
 
Hi,

if you have a file "chk" like this:
Code:
   with blanks
without
  with blanks again
without blanks but with "special chars"
 with blanks and \special chars$

you can use awk to insert text like that:
Code:
cat chk | awk '{if( $1 ~ /without/)print "insert"; print; }'

ciao, mbr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top