Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Linux: Process file in reverse

This returns the number 200 just as it should, because there are 200 lines in the file:
#!/bin/bash
while read MONTH DAY TIME DATA
do
 COUNT=$((COUNT+1))
done < $1
echo $COUNT

Open in new window

When I try to do this in reverse it returns 1.
#!/bin/bash
while read MONTH DAY TIME DATA
do
 COUNT=$((COUNT+1))
done <<< $(tac $1)
echo $COUNT

Open in new window

I am using CentOS.
0
hankknight
Asked:
hankknight
1 Solution
 
woolmilkporcCommented:
#!/bin/bash
while read MONTH DAY TIME DATA
do
 COUNT=$((COUNT+1))
done <<< "$(tac $1)"
echo $COUNT

Open in new window


i.e. put quotes around "$(tac $1)", otherwise the newlines will be stripped. I didn't take this into account (I simply forgot about this behaviour) in my comments to your previous threads. Sorry!
0
 
hankknightAuthor Commented:
Thanks!  That explains everything.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now