Solved

Linux: Process file in reverse

Posted on 2013-11-18
2
202 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
ID: 39657358
#!/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
ID: 39657381
Thanks!  That explains everything.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
docker invalid registry name 2 104
PC upgrade to Linux Mint 7 64
nagios 1 21
Recommendations for Web-Based Multi-User File Manager / FTP software? 4 54
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

937 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

7 Experts available now in Live!

Get 1:1 Help Now