?
Solved

printig 20 lines from string

Posted on 2008-11-13
6
Medium Priority
?
378 Views
Last Modified: 2013-12-26
hi  I need to write an awk script that prints 20 lines from a string and directs output to a file.
pls help.
0
Comment
Question by:mbpssgms
6 Comments
 
LVL 14

Expert Comment

by:mikelfritz
ID: 22949899
Can you give an example of the input and desired output?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22952989
How does your string store 20 lines?
0
 
LVL 20

Expert Comment

by:edster9999
ID: 22956056
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:mikelfritz
ID: 22957032
The question needs clarification.  At this point all we could do is guess at the i/o.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1000 total points
ID: 23650787
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
 

Author Closing Comment

by:mbpssgms
ID: 31516348
thanks I'd been away.  This was similar to another solution.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question