Solved

Linux: Process file in reverse

Posted on 2013-11-18
2
200 Views
Last Modified: 2013-11-18
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
Comment
Question by:hankknight
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
#!/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
 
LVL 16

Author Closing Comment

by:hankknight
Comment Utility
Thanks!  That explains everything.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
NTP Server in VMware 5 115
Webserver access problem 5 62
apply ddos protection on all network interface 2 50
linux crontab output 3 36
In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now