Solved

How can I remove a record from a large Unix file ?

Posted on 2011-03-25
6
801 Views
Last Modified: 2012-05-11
I have a Unix file that has a bad record in it that needs removed.

The file is too large for vi, it says "No space left on device".

So how can I remove the bad record ? it has "MB6     0" in position 86 for 9.

Through other testing, I also know what record # it is.
0
Comment
Question by:Alaska Cowboy
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 75 total points
ID: 35215827
If you have enough space to store the big file twice:

    sed NNd bigfile > bigfile.copy

where NN is the record number (e.g. "sed 2d bigfile > bigfile2" to remove line 2).
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35215845
This assumes that the "record" is a text line.  If this is a file sith some other format (fixed-length fields, binary values and so on) then "sed" won't work.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35215847
This assumes that the "record" is a text line.  If this is a file sith some other format (fixed-length fields, binary values and so on) then "sed" won't work.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 50 total points
ID: 35215884
awk  '{if(substr($0,86,9)!="MB6     0") print}' largefile > largefile.tmp
mv largefile.tmp largefile

wmp
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 35216001
simon and woolmilkporc, thanks ! I will try both options.
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 35216126
ok, both worked ! thanks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert grep lines to perl 6 35
Find characters between pattern in a file linux 3 46
Martian Packets Unix 5 50
awk sed 8 39
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now