07-05-2012
I misunderstood your request.. I thought looking at your script and your post that you wanted the value of line of first file for each line (every - all...) lines of file 2 ) of file 2 in which case imbricated loops made sense...
I think ctsgnb's proposal is the way to go, but to help you more we would need to know the content of the files, there may be something tricky we are not aware of...
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Could any one tell me how to read and match multiple lines in perl? Did this code below still work in this situation?
while (<FILE>) {
if (/ /) {
}
}
Thanks a lot! (5 Replies)
Discussion started by: zx1106
5 Replies
2. Shell Programming and Scripting
Hello,
I have three lines I need to add to hundreds of files. The files are all in the same format and contain the same information. I want to add the same information to the files.
The new lines of information are similar. Here is an example of the three lines:
line1:
line2 =... (2 Replies)
Discussion started by: dayinthelife
2 Replies
3. Shell Programming and Scripting
i have to search a string and replace with multiple lines.
example
Input
echo 'sample text'
echo 'college days'
output
echo 'sample text'
echo 'information on students'
echo 'emp number'
echo 'holidays'
i have to search a word college and replace the multiple lines
i have... (1 Reply)
Discussion started by: unihp1
1 Replies
4. Shell Programming and Scripting
Hi All,
Does anyone know how to read multiple lines from standard input into an array and then iterate a loop for all the lines read. Below is an example pseudocode:
I need the below filenames to be read by the script into an array or something similar:
And then in the script, I... (9 Replies)
Discussion started by: bharath.gct
9 Replies
5. Shell Programming and Scripting
Hi all,
I am just trying to read the contents of a file. basically this file has a list of dat files. then i want to access these dat files n execute a script on them one by one using a loop.
i hav e written like this
ls -l | cut -c 58-88 > file1.txt
while
do
arr1="$( sed -n '1p'... (7 Replies)
Discussion started by: navjyotisonu5
7 Replies
6. Shell Programming and Scripting
I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field.
example input line:
... (2 Replies)
Discussion started by: erlanq
2 Replies
7. Shell Programming and Scripting
I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field.
example input line:
... (1 Reply)
Discussion started by: erlanq
1 Replies
8. Shell Programming and Scripting
Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ?
The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories.
So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies
9. Shell Programming and Scripting
Hello All,
I have a file like below....
dn: cn=user1,ou=org,o=org
cn=user1
uid=user1
cn=user2,ou=org,o=org
cn=user2
uid=user2
cn=user3,ou=org,o=org
cn=user3
cn=user33
uid=user3
cn=user4,ou=org,o=org
cn=user4
uid=user4 (6 Replies)
Discussion started by: s_linux
6 Replies
10. Shell Programming and Scripting
Hello Gurus,
I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file.
1|ABC DEF|100|10
2|PQ
RS
T|200|20
3| UVWXYZ|300|30
4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies
LEARN ABOUT CENTOS
ppi::token::heredoc
PPI::Token::HereDoc(3) User Contributed Perl Documentation PPI::Token::HereDoc(3)
NAME
PPI::Token::HereDoc - Token class for the here-doc
INHERITANCE
PPI::Token::HereDoc
isa PPI::Token
isa PPI::Element
DESCRIPTION
Here-docs are incredibly handy when writing Perl, but incredibly tricky when parsing it, primarily because they don't follow the general
flow of input.
They jump ahead and nab lines directly off the input buffer. Whitespace and newlines may not matter in most Perl code, but they matter in
here-docs.
They are also tricky to store as an object. They look sort of like an operator and a string, but they don't act like it. And they have a
second section that should be something like a separate token, but isn't because a strong can span from above the here-doc content to below
it.
So when parsing, this is what we do.
Firstly, the PPI::Token::HereDoc object, does not represent the "<<" operator, or the "END_FLAG", or the content, or even the terminator.
It represents all of them at once.
The token itself has only the declaration part as its "content".
# This is what the content of a HereDoc token is
<<FOO
# Or this
<<"FOO"
# Or even this
<< 'FOO'
That is, the "operator", any whitespace separator, and the quoted or bare terminator. So when you call the "content" method on a HereDoc
token, you get '<< "FOO"'.
As for the content and the terminator, when treated purely in "content" terms they do not exist.
The content is made available with the "heredoc" method, and the name of the terminator with the "terminator" method.
To make things work in the way you expect, PPI has to play some games when doing line/column location calculation for tokens, and also
during the content parsing and generation processes.
Documents cannot simply by recreated by stitching together the token contents, and involve a somewhat more expensive procedure, but the
extra expense should be relatively negligible unless you are doing huge quantities of them.
Please note that due to the immature nature of PPI in general, we expect "HereDocs" to be a rich (bad) source of corner-case bugs for quite
a while, but for the most part they should more or less DWYM.
Comparison to other string types
Although technically it can be considered a quote, for the time being "HereDocs" are being treated as a completely separate "Token"
subclass, and will not be found in a search for PPI::Token::Quote or "PPI::Token::QuoteLike objects".
This may change in the future, with it most likely to end up under QuoteLike.
METHODS
Although it has the standard set of "Token" methods, "HereDoc" objects have a relatively large number of unique methods all of their own.
heredoc
The "heredoc" method is the authoritative method for accessing the contents of the "HereDoc" object.
It returns the contents of the here-doc as a list of newline-terminated strings. If called in scalar context, it returns the number of
lines in the here-doc, excluding the terminator line.
terminator
The "terminator" method returns the name of the terminating string for the here-doc.
Returns the terminating string as an unescaped string (in the rare case the terminator has an escaped quote in it).
TO DO
- Implement PPI::Token::Quote interface compatibility
- Check CPAN for any use of the null here-doc or here-doc-in-s///e
- Add support for the null here-doc
- Add support for here-doc in s///e
SUPPORT
See the support section in the main module.
AUTHOR
Adam Kennedy <adamk@cpan.org>
COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl v5.16.3 2011-02-26 PPI::Token::HereDoc(3)