PDA

View Full Version : how to print multiple line


akhilesh
10-12-2006, 07:23 AM
Hi All,
can you please tell me how to print multiple [contine ] line by useing
shell script.

TEST_DESCRIPTION \
"this is the program which used to \
add some of two digit\
the no should be integer but not float\
not even character"
if i want search TEST_DESCRIPTION \
and then print all line
i am using grep -A 7 'TEST_DESCRIPTION' file name but it will display 7 line
but at different file having different TEST_DESCRIPTION .
So plz tell me what can i do.
thx
Akhilesh

acme.mail.order
10-12-2006, 08:11 AM
Assuming that your printers are set up correctly,

grep -A 7 'TEST_DESCRIPTION' "file name" | lpr

should send the output to your printer.
For fancier results, try:

grep -A 7 'TEST_DESCRIPTION' "file name" > ~/Desktop/output.txt

then do whatever you wish with the resulting textfile.

hayne
10-12-2006, 09:37 AM
If I understand you correctly, the problem is how to extract all of the lines from the line starting with "TEST_DESCRIPTION" until the next unescaped newline.

You can do that with the following one line Perl script (assuming that your text is in a file named "foo"):

perl -lne 'print if /^TEST_DESCRIPTION/ .. /[^\\]$/' foo

Explanation of the above:
The "-lne" makes Perl automatically loop over all lines in the file and remove the newline on each line while executing the specified command.
The command
'print if /^TEST_DESCRIPTION/ .. /[^\\]$/'
says to print all lines from a line that starts with "TEST_DESCRIPTION"
("^" marks the start of the line)
to the first succeeding line that ends with anything other than a backslash.
("[^\\]" indicates a single character that is not a backslash, "$" marks the end of the line)

The following is an enhancement of the above that allows for arbitrary whitespace ("\s*") at the beginning of the "TEST_DESCRIPTION" line.

perl -lne 'print if /^\s*TEST_DESCRIPTION/ .. /[^\\]$/' foo