How to delete the lines from file using script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete the lines from file using script?
# 1  
Old 02-13-2013
How to delete the lines from file using script?

Hi

Iam having file like below

HTML Code:
10.238.52.65 pun-ras-bng-mhs-01 server
10.238.52.65 pun-ras-bng-mhs-01 10.10.10.10
10.238.52.65 pun-ras-bng-mhs-01 10.10.20.10
10.238.54.1 enk-ras-bng-cse-01 server
10.238.54.1 enk-ras-bng-cse-01 10.10.30.10
10.238.54.1 enk-ras-bng-cse-01 10.10.10.10
Required output file
HTML Code:
10.238.52.65 pun-ras-bng-mhs-01 10.10.10.10
10.238.52.65 pun-ras-bng-mhs-01 10.10.20.10
10.238.54.1 enk-ras-bng-cse-01 10.10.30.10
10.238.54.1 enk-ras-bng-cse-01 10.10.10.10
I dont need the lines which having word server in output file. can any body help.

tnx in advance.
# 2  
Old 02-13-2013
Code:
awk '!/server/' infile > outfile

This User Gave Thanks to Jotne For This Post:
# 3  
Old 02-13-2013
hi
tnx ,its working fine
# 4  
Old 02-13-2013
Hi Reddy,

Code:
 sed "/server/d" $file

If you want to reflect the original file

Code:
 sed -i "/server/d" $file

This User Gave Thanks to srinivas matta For This Post:
# 5  
Old 02-13-2013
if you were looking for the server clause at the end of the file so that its doesn't affect , found in other columns,

Code:
sed -e '/server$/D'  filenames
10.238.52.65 pun-ras-bng-mhs-01 10.10.10.10
10.238.52.65 pun-ras-bng-mhs-01 10.10.20.10
10.238.54.1 enk-ras-bng-cse-01 10.10.30.10
10.238.54.1 enk-ras-bng-cse-01 10.10.10.10

# 6  
Old 02-13-2013
Test only the last field
Code:
awk '$NF!="server"' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

script to delete lines from a txt file if pattern matches

File 6 dbnawldb010-b office Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/09/11 03:24:04 42 luigi-b IPNRemitDB Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/10/11 00:41:36 6 ebs-sqldev1-b IPNTracking Memphis_Corp_SQL_Diff... (4 Replies)
Discussion started by: ajiwww
4 Replies

3. Shell Programming and Scripting

looking for a script that will delete lines in a text file

it will grep for a line and then delete these line. how do i begin to write this script if theres no available one? (3 Replies)
Discussion started by: garfish
3 Replies

4. Shell Programming and Scripting

HP Unix Script to Delete the lines in a file

Hi Experts, I have a file format as mentioned below. I would like to have unix script (HP Unix) which can: 1. Remove first 6 and last 3 lines. 2. Delete the lines where 3rd column having Alpha Numeric Number 3. Delete the lines where 4th column having 0.00 4. Calculate the sum of all the... (16 Replies)
Discussion started by: phani333
16 Replies

5. Shell Programming and Scripting

Delete lines from file using Unix Script

Hi Experts, I have a file in the below given format. First two lines are header and Trailer. Rest all are transaction Lines. I have to delete all other lines except first line (Header) and lines which contains 5000 in 1st column and 0 in 5th column. Can anyone please kindly provide me with... (6 Replies)
Discussion started by: phani333
6 Replies

6. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

7. 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

8. Shell Programming and Scripting

How to delete lines in a file that have duplicates or derive the lines that aper once

Input: a b b c d d I need: a c I know how to get this (the lines that have duplicates) : b d sort file | uniq -d But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Discussion started by: necroman08
3 Replies

9. Shell Programming and Scripting

Delete lines at several places in a file with script

Hi, I am a newbie to shell scripting, and I have a file which quite large which I would like to delete lines at certain places. I want to search for a keyword which is recurring in the file. When matched I would like to delete the line. And when the file was so huge I thought I ought to learn... (3 Replies)
Discussion started by: mr_andrew
3 Replies

10. Shell Programming and Scripting

How to Delete all lines in a file from a script

I am trying to delete all the lines out a file from a unix script. Please help Platform is Sun (3 Replies)
Discussion started by: alnita
3 Replies
Login or Register to Ask a Question