Deleting a line from a flatfile using Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting a line from a flatfile using Shell Script
# 1  
Old 06-23-2009
Question Deleting a line from a flatfile using Shell Script

Hi All,
Can Anyone please tell me,how can I delete a line from a file.
I am reading the file line by line using whil loop and validating each line..Suppose in the middle i found a particular line is invalid,i need to delete that particular line.
Can anyone please help.
Thanks in advance,
Dinesh
# 2  
Old 06-23-2009
you may redirect the output to a new file, while writing all the lines in the loop except for the ones you dont want...else
try sed, grep, awk anything.
# 3  
Old 06-23-2009
Thanks for ur reply..
Can you please help me in writing the command using sed/awk. I am a beginner in UNIX.
# 4  
Old 06-23-2009
search for the awk or sed manual...
atleast give some try...
# 5  
Old 06-23-2009
I have tried with sed -i and sed -d ..but it is not working
# 6  
Old 06-23-2009
show your code.
sample input,
validation pattern, and
expected output
# 7  
Old 06-23-2009
Example

input file
First Name - position from 1-5
Last Name- position 6-10
Age-Position 11-12
Say above is the format of input file.
Example:
DINESKUMAR21
SACHISHAH 23
23
GURUNTARIM22

In the above example,in the 3 rd record Name is missing. Now while reading the file line by line,I want to delete the 3 rd line during validation.

---------- Post updated at 08:47 AM ---------- Previous update was at 08:46 AM ----------

for the third line blankspaces will be present before 23
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command within script wrongly deleting the last line

Hi, I have a shell script which has a for loop that scans list of files and do find and replace few variables using sed command. While doing this, it deletes the last line of all input file which is something wrong. how to fix this. please suggest. When i add an empty line in all my input file,... (5 Replies)
Discussion started by: rbalaj16
5 Replies

2. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

3. Shell Programming and Scripting

Script for identifying and deleting dupes in a line

I am compiling a synonym dictionary which has the following structure Headword=Synonym1,Synonym2 and so on, with each synonym separated by a comma. As is usual in such cases manual preparation of synonyms results in repeating the synonym which results in dupes as in the example below:... (3 Replies)
Discussion started by: gimley
3 Replies

4. Shell Programming and Scripting

Problem to get yesterday's date flatfile with shell script

hi, i was required to write a shell script to get yesterday's date flatfile. but i only know how to get today's date flatfile. Please observed my below scripting: Please help! Thanks ================================================= #!/bin/sh HOST='192.168.1.200' USER='ftp1'... (19 Replies)
Discussion started by: lifeseries
19 Replies

5. Shell Programming and Scripting

Finding a flatfile & deleting first line

I have a small script where I want to see if a file exists & then delete the first line from it. I have code to help me find if the file exists, but I am unsure as to how to then take in the answer and remove the first line from the flatfile: This is what I have so far just to output if the... (3 Replies)
Discussion started by: fatalxkiss
3 Replies

6. Shell Programming and Scripting

Shell Script for deleting the first line in a file

Hi, Could any one please post the shell script for deleting the first line in a file? (3 Replies)
Discussion started by: badrimohanty
3 Replies

7. Shell Programming and Scripting

shell script reqd - deleting files

I have written a script that deletes files: Requirement: i need to delete the files and to know how many files are deleted i.e the count of files and even i need to display when the started time of deletion and the ending time of deletion. I need to display these two times. script: ... (2 Replies)
Discussion started by: venkatesht
2 Replies

8. Shell Programming and Scripting

Deleting column from a flatfile with delimiter

I have a set of flatfiles which have columns delimited by #. How can a particular column be deleted in all the flatfiles. All flatfiles have same number of columns. (5 Replies)
Discussion started by: rsprabha
5 Replies

9. Shell Programming and Scripting

Urgent help required in deleting a line without opening a file usinga shell script

Hi, I need a help in deleting a line matching a particular pattern in a file using shell script without opening the file. The file is a .c/.cpp file. Is it possible? Thanks (6 Replies)
Discussion started by: naan
6 Replies

10. Shell Programming and Scripting

shell script: deleting files from a directory

i have the following problem: use shell script: Two directories have to be searched for files havin the same name. then delete these files from one of these directories. the directory names have to be accepted as command line arguments. what i have done till now is: 1. run a loop... (1 Reply)
Discussion started by: onlyc
1 Replies
Login or Register to Ask a Question