Leaving last 30 lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Leaving last 30 lines
# 1  
Old 01-10-2013
Leaving last 30 lines

If we want to display lines from file leaving last 30 lines. i dont know the count of lines in file
# 2  
Old 01-10-2013
Code:
 
tail -r temp | nawk 'NR>30'|tail -r


Last edited by Scott; 01-10-2013 at 09:18 AM.. Reason: Removed link
# 3  
Old 01-10-2013
You can also try:
Code:
awk 'NR==FNR{n=NR;next}FNR<=n-c-1' c=30 file file

# 4  
Old 01-10-2013
Or:
Code:
awk 'NR>c{print A[NR%c]} {A[NR%c]=$0}' c=30 file

# 5  
Old 01-10-2013
can you pls give me a sample output and explain me what command does..will be very helpful. thank you
# 6  
Old 01-10-2013
Sed and awk are both fast method.

Code:
lines=$(cat x.txt | wc -l)  # numberOfLines

echo "--------------------------"
# delete lines between 1-$line = rest is output
sed  "1,${line}d" x.txt

echo "--------------------------"
((line=line-1))  
# print (p) starting from line $line to end
sed -n "$line,\$p" x.txt

# 7  
Old 01-10-2013
Thanks kshji

But I want output using one command, not a script

---------- Post updated at 10:12 PM ---------- Previous update was at 10:09 PM ----------

kshji
Code:
tail -r temp | nawk 'NR>30'|tail -r

is this command working?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to delete identical lines while leaving one undeleted?

Hi, I have a file as follows. file1 Hello Hi His Hi Hi Hungry hi so I want to delete identical lines while leaving one of them undeleted. So desired output will be Hello Hi (2 Replies)
Discussion started by: beginner_99
2 Replies

2. Shell Programming and Scripting

Leaving directory Error

Hi, i have a question, when I install any software it give error message like as follow : sudo make password for csm: make all-recursive make: Entering directory `/home/csm/Desktop/miRanda-3.3a' Making all in man make: Entering directory `/home/csm/Desktop/miRanda-3.3a/man' make:... (18 Replies)
Discussion started by: harpreetmanku04
18 Replies

3. Shell Programming and Scripting

Leaving space inside sed

Hi Gurus, I have 2 files File1 : veg apple ap pl le end veg orange or an ge end File2: (2 Replies)
Discussion started by: jayadanabalan
2 Replies

4. Red Hat

How to compare file leaving certain filelds?

How to compare two files leaving certain fields, using diff command the entire file is being compared. Can any one please help. (5 Replies)
Discussion started by: ramsavi
5 Replies

5. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

6. Shell Programming and Scripting

Leaving for loop on condition

hi all, i have a problem...no dream :-) i want to scan a file i use the loop famous while read line do do < myfile but this scan must finish when find the another string . How can i do it? best regards for all. Francesco Please use descriptive subjects. "script." doesn't tell... (5 Replies)
Discussion started by: FrancescoIt
5 Replies

7. UNIX for Dummies Questions & Answers

Delete all rows but leaving first and last ones

Hello, Merry Christmas to all! I wish you the best for these holidays and the best for the next year 2011. I'd like your help please, I need to delete all the rows in the third column of my file, but without touching nor changing the first and last value position, this is an example of my... (2 Replies)
Discussion started by: Gery
2 Replies

8. Shell Programming and Scripting

Remove lines of the same time stamp leaving the highest

Hi guys, I have a log that looks like that below. Columns 2 3 4 5 6 7 is the date/time stamp separated by comma. UUU,02,06,2010,10,00,00,00,0000000000000000,0000000000000000,0000000000001224 UUU,02,06,2010,10,05,00,00,0000000000000000,0000000000000000,0000000000001502... (2 Replies)
Discussion started by: borderblaster
2 Replies

9. Solaris

leaving ALOM mode

Some netra 240 machines went into ALOM mode, and when I issue the command; sc> console it got stuck, does it mean Solaris OS had crashed ? or what can I do to reboot,because reboot is not starting? And advice ? (3 Replies)
Discussion started by: xramm
3 Replies
Login or Register to Ask a Question