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?
 
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.
0
 
mikelfritzCommented:
Can you give an example of the input and desired output?
0
 
TintinCommented:
How does your string store 20 lines?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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

0
 
mikelfritzCommented:
The question needs clarification.  At this point all we could do is guess at the i/o.
0
 
mbpssgmsAuthor Commented:
thanks I'd been away.  This was similar to another solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.