05-16-2008
Deleting lines in text file
Hi everyone,
I have text files that I want to delete lines from. I have searched through this forum for quite some time and found examples of both awk and sed. Unfortunately, I was not able to successfully do what I want. Well to some extent. I did manage to delete the first 15 lines from each of the text files, since all the text files will have the same first 15 lines.
So, I have a text file that looks like this:
Id First Name Last Name
--- ---------- ---------
1 Mary Jane
2 Joe Blowe
2 record(s) selected.
Return Status = 0
Notice the lines in bold....every text file will have this at the end. This file will be emailed and the recepients won't have a clue to what those two lines mean, so I would like to remove them. Any suggestions? THANKS!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have a file & always I need to remove or delete last 2 lines from that file. So in a file if I have 10 lines then it should return me first 8 lines.
Can someone help me? (4 Replies)
Discussion started by: videsh77
4 Replies
2. Shell Programming and Scripting
How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too.
Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies
3. Shell Programming and Scripting
I have a directory full of text data files.
Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application.
I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate... (3 Replies)
Discussion started by: vrms
3 Replies
4. UNIX for Dummies Questions & Answers
I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies
5. UNIX for Advanced & Expert Users
How I can delete 100 lines anywhere in a file without opening a file and without renaming the file. (11 Replies)
Discussion started by: Nirgude07
11 Replies
6. Shell Programming and Scripting
We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies
7. UNIX for Dummies Questions & Answers
Hi,
I have a space delimited text file that looks like the following:
250 rs10000056 0.04 0.0888 4 189321617
250 rs10000062 0.05 0.0435 4 5254744
250 rs10000064 0.02 0.2403 4 127809621
250 rs10000068 0.01 NA
250 rs1000007 0.00 0.9531 2 237752054
250 rs10000081 0.03 0.1400 4 17348363... (5 Replies)
Discussion started by: evelibertine
5 Replies
8. Shell Programming and Scripting
Hi,
I'm trying to search for some number and from that line, i need to delete the 5th line exactly.
Eg:
Consider below as text file data:
10000
a
b
c
d
e
.
.
.
10000
w
q
t (8 Replies)
Discussion started by: Gautham
8 Replies
9. Shell Programming and Scripting
Hi!
I want to delete N (say 10) lines after the line which text is found in a file "A".Also to delete the line in which the text is found.
Only one occurrence of the search string in the file "A"
The text to be deleted is in another text file "B". All the search texts in the file "B" are in... (3 Replies)
Discussion started by: shahid1632
3 Replies
10. Shell Programming and Scripting
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
file1.txt
abc12345
def12345
ghi54321
...
file2.txt
abc1,text1,texta
abc,text2,textb
def123,text3,textc
gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
SDIFF(1) GNU Tools SDIFF(1)
NAME
sdiff - find differences between two files and merge interactively
SYNOPSIS
sdiff -o outfile [options] from-file to-file
DESCRIPTION
The sdiff command merges two files and interactively outputs the results to outfile.
If from-file is a directory and to-file is not, sdiff compares the file in from-file whose file name is that of to-file, and vice versa.
from-file and to-file may not both be directories.
sdiff options begin with -, so normally from-file and to-file may not begin with -. However, -- as an argument by itself treats the
remaining arguments as file names even if they begin with -. You may not use - as an input file.
sdiff without -o (or --output) produces a side-by-side difference. This usage is obsolete; use diff --side-by-side instead.
Options
Below is a summary of all of the options that GNU sdiff accepts. Each option has two equivalent names, one of which is a single letter
preceded by -, and the other of which is a long name preceded by --. Multiple single letter options (unless they take an argument) can be
combined into a single command line argument. Long named options can be abbreviated to any unique prefix of their name.
-a Treat all files as text and compare them line-by-line, even if they do not appear to be text.
-b Ignore changes in amount of white space.
-B Ignore changes that just insert or delete blank lines.
-d Change the algorithm to perhaps find a smaller set of changes. This makes sdiff slower (sometimes much slower).
-H Use heuristics to speed handling of large files that have numerous scattered small changes.
--expand-tabs
Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files.
-i Ignore changes in case; consider upper- and lower-case to be the same.
-I regexp
Ignore changes that just insert or delete lines that match regexp.
--ignore-all-space
Ignore white space when comparing lines.
--ignore-blank-lines
Ignore changes that just insert or delete blank lines.
--ignore-case
Ignore changes in case; consider upper- and lower-case to be the same.
--ignore-matching-lines=regexp
Ignore changes that just insert or delete lines that match regexp.
--ignore-space-change
Ignore changes in amount of white space.
-l
--left-column
Print only the left column of two common lines.
--minimal
Change the algorithm to perhaps find a smaller set of changes. This makes sdiff slower (sometimes much slower).
-o file
--output=file
Put merged output into file. This option is required for merging.
-s
--suppress-common-lines
Do not print common lines.
--speed-large-files
Use heuristics to speed handling of large files that have numerous scattered small changes.
-t Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files.
--text Treat all files as text and compare them line-by-line, even if they do not appear to be text.
-v
--version
Output the version number of sdiff.
-w columns
--width=columns
Use an output width of columns. Note that for historical reasons, this option is -W in diff, -w in sdiff.
-W Ignore horizontal white space when comparing lines. Note that for historical reasons, this option is -w in diff, -W in sdiff.
SEE ALSO
cmp(1), comm(1), diff(1), diff3(1).
DIAGNOSTICS
An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.
GNU Tools 22sep1993 SDIFF(1)