Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to figure out way to take the

Status
Not open for further replies.

Natalie30

Programmer
Feb 5, 2003
12
0
0
US
need to figure out way to take the end of a log file value and take that value and add it to the end of the next line. So it would look something like this.
"x","x","x","100"
"x","x","x","200"
"x","x","x","400"
should turn into
"x","x","x","100","0"
"x","x","x","200","100"
"x","x","x","400","200"
have any suggestions
 
One way would be:

[tt]$last = '"0"';

while (<>) {
chomp;
@x = split ',';
print &quot;$_,$last\n&quot;;
$last = $x[$#x];
}
[/tt]

split will split up a string based on the passed delimiter and return the portions as a list. (The delimiter can be a regular expression.)

[tt]$x[$#x][/tt] is the last element of the list @x. I believe you could also say [tt]$x[-1][/tt] to accomplish the same thing.
 
Heres what my file looks like when i pull it up.
&quot;Wed Feb 5 23:50:00 2003&quot;,&quot;1.24&quot;,&quot;68&quot;,&quot;111&quot;,&quot;41576&quot;

what i need to do is take that last value &quot;41576&quot; and add it to the end of the next line that prints out in the log file. like this.
&quot;Wed Feb 5 23:50:00 2003&quot;,&quot;1.24&quot;,&quot;68&quot;,&quot;111&quot;,&quot;41576&quot;,&quot;0&quot;
&quot;Wed Feb 5 23:51:00 2003&quot;,&quot;1.55&quot;,&quot;77&quot;,&quot;119&quot;,&quot;40527&quot;,&quot;41576&quot;
&quot;Wed Feb 5 23:52:00 2003&quot;,&quot;1.33&quot;,&quot;55&quot;,&quot;113&quot;,&quot;33165&quot;,&quot;40527&quot;

this is the result i need. Thank you sooo much for your help. Nat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top