printig 20 lines from string

hi  I need to write an awk script that prints 20 lines from a string and directs output to a file.
pls help.
mbpssgmsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikelfritzCommented:
Can you give an example of the input and desired output?
TintinCommented:
How does your string store 20 lines?
edster9999Commented:
strings in shell scripts do not have \n or \r or anything like that in tham as far as I know.

If you have managed to get new lines into a string then you could echo it and then pipe it to head and then pipe that into a file

echo "$string" | head -n 20 > /path/file.txt

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mikelfritzCommented:
The question needs clarification.  At this point all we could do is guess at the i/o.
ahoffmannCommented:
assuming string (as asked for in the original question) is in file named string.txt:

head -20 string.txt>file
tail -20 string.txt>file
sed -ne '1,20p' string.txt>file
awk '(NR<21){print}' string.txt>file
awk 'END{printf"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}' string.txt>file

Note: only the last examples ensures that you realy get 20 lines.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbpssgmsAuthor Commented:
thanks I'd been away.  This was similar to another solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.