LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 02-01-2018, 09:29 PM   #1
Swathi Prasad
LQ Newbie
 
Registered: Jan 2018
Posts: 17

Rep: Reputation: Disabled
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?

Last edited by Swathi Prasad; 02-01-2018 at 09:34 PM.
 
Old 02-01-2018, 09:34 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,146

Rep: Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935Reputation: 2935
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.
 
Old 02-02-2018, 06:16 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,061
Blog Entries: 13

Rep: Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503Reputation: 3503
@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.
 
1 members found this post helpful.
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script command for file modification hwang163 Linux - General 2 06-14-2014 01:20 AM
ls command modification/creation date with full century value devUnix Solaris / OpenSolaris 1 02-01-2011 11:25 AM
Command line - command modification eric2233 Linux - Software 2 12-28-2006 02:13 PM
write a command whose modification time is changed in min suchi_s Programming 1 09-08-2004 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration