LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   modification to the command (https://www.linuxquestions.org/questions/linux-newbie-8/modification-to-the-command-4175622902/)

Swathi Prasad 02-01-2018 09:29 PM

modification to the command
 
Hi,

My file has the following text

Code:


SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
Total number:34

for the below command

Code:


tac file | awk '!NF {print};NF {if (n) {print} else {n=1}}'

I am expecting it to give the below output(1)(deleting last line)


Code:


SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09

instead,it is giving the below output(2).(deleting last 2 lines)


Code:


SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09


only if some empty line(s) is there at the end of the file,then only it is giving the output(1).


The file is as shown below.

Code:


SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09
Total number:34
<<empty line>>

Unable to understand the difference?

syg00 02-01-2018 09:34 PM

That was given to you as the answer to a specific query.
You need to make an effort to understand the code before you ask for yet another solution. Else you'll never learn.

rtmistler 02-02-2018 06:16 AM

@Swathi Prasad,

These repeated questions providing zero effort on your part are unacceptable on the LQ site.

You have been referred to our links about how to ask effective questions and informed how the LQ site works on each prior occasion.

This thread and others have been closed to avoid further frustrations on the part of fellow LQ members.

If you persist with repeating this manner of posting, your posting privileges may be affected.


All times are GMT -5. The time now is 02:22 AM.