Solved

Linux: Process file in reverse

Posted on 2013-11-18
2
205 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

803 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