Solved

Linux: Process file in reverse

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access_log 17 144
Reset Root Password on CentOS 6 4 69
Choosing CentOS 16 106
Remove Resilio directory from Netgear ReadyNAS 212 via SSH. 2 46
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

789 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