How to select/delete some lines in shell?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to select/delete some lines in shell?
# 1  
Old 08-11-2011
How to select/delete some lines in shell?

I need to delete half(approx) the file or select half the file by existence of some character

My file looks like

1
2
3
4
.
.
.
50
.
.
100
I need to select only 50 to rest of the file or needs to delete the file upto 50.

Please help me out..
# 2  
Old 08-11-2011
Code:
tail +51 inputfile

# 3  
Old 08-11-2011
That was an example of my file.. My file does not have any numbers. So i need to select it from the existence of Particular Character, For Example,

Event ID =1
.
.
.
.
EventID=25
.
.
.
.
EventID=50

I need to select from "EventID=25" to rest of the file.
# 4  
Old 08-11-2011
Code:
sed -n '/EventID=25/,$p' inputfile

Jean-Pierre.
# 5  
Old 08-11-2011
Code:
deleted

# 6  
Old 08-12-2011
EventID=25/,$d' inputfile
ther should be d instead if p
# 7  
Old 08-12-2011
Depends, the OP asked "Select from EventID=25 to the end", now it depends on how you interpret select. I personally think select means display. Plus if you use d with "sed -n" nothing will get printed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to merge and delete lines

POLY_STATS { EqName 103_tri Id 123 act_polyCount 1 act_polyValue 0 } POLY_STATS { EqName 103_tri Id 123 pass_polyCount 2 pass_polyValue 0 } POLY_STATS { EqName 103 Id 123 mes_polyCount 2 mes_polyValue 0 (5 Replies)
Discussion started by: Jag02
5 Replies

2. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies

3. Shell Programming and Scripting

Select lines where at least x columns above threshold value

I have a file with 20 columns. I'd like to retain only the lines for which the values in at least x columns, looking only at columns 6-20, are above a threshold. For example, I'd like to retain only the lines in the file below that have at least 8 columns (again, looking only at columns 6-20)... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

4. UNIX for Dummies Questions & Answers

How to delete lines above a certin line number in bash shell

Hi, I have written a script that returns the line number of the pattern i want and i stored the line number in a variable.Now i want to delete all the lines in a file above this line number which is stored in a variable. i am using sed '1,$getlinenumberd' > file1.txt which is not working(wrog... (5 Replies)
Discussion started by: learninguser235
5 Replies

5. UNIX for Dummies Questions & Answers

How to delete lines above a certin line number in bash shell

Hi, I have written a script that returns the line number of the pattern i want and i stored the line number in a variable(getlinenumber).Now i want to delete all the lines in a file above this line number which is stored in a variable. i am using sed '1,$getlinenumberd' > file1.txt which is... (2 Replies)
Discussion started by: learninguser235
2 Replies

6. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

7. Shell Programming and Scripting

select the lines in between some time span

Hi Everyone ! i want to take all the lines from a file that falls in between some date... and every line in a file has a time stamp.. ---some text---- 01/Jan/2010 ---- some other text ---- ---some text---- 10/Jan/2010 ---- some other text ---- ---some text---- 20/Dec/2010 ---- some... (3 Replies)
Discussion started by: me_newbie
3 Replies

8. Shell Programming and Scripting

Delete blank lines, if blank lines are more than one using shell

Hi, Consider a file named "testfile" The contents of file are as below first line added for test second line added for test third line added for test fourth line added for test fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies

9. Shell Programming and Scripting

Select lines in which column have value greater than some percent of total file lines

i have a file in following format 1 32 3 4 6 4 4 45 1 45 4 61 54 66 4 5 65 51 56 65 1 12 32 85 now here the total number of lines are 8(they vary each time) Now i want to select only those lines in which the values... (6 Replies)
Discussion started by: vaibhavkorde
6 Replies

10. Shell Programming and Scripting

Need Shell Script to delete lines in a file

Hi All, I have a file with 3 columns (Bank Name, Account Number and Amount). My requirement, I need to delete lines using Unix Shell script: 1. Which are having Alphanumeric characters in Account Number (eg. Line3). 2. Which are having 0.00 in amount. (eg. Line4) 3. And also I need to... (4 Replies)
Discussion started by: phani333
4 Replies
Login or Register to Ask a Question