|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to remove the first line from a flat file ?
Hi,
I want to remove the first line from a flat file using unix command as simple as possible. Can anybody give me a hand ? Thanks in advance. xli |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
printf ":1d\n:wq\n" | ex name_of_your_flatfile
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
another way,
sed -i '1d' filename |
|
#4
|
||||
|
||||
|
That does not remove the line from the file, is streams the file to stdout with the first line removed. It would need to be redirected into a temporary file and moved back to replace the original file.
Also if I am correct, and I remember correctly the flatfile xli is talking about is pretty huge (millions of lines), and do it that way could be pretty slow. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
thanks for the explanation. i give another reply
perl -pi -e '$_ = "" if ($. == 1);' filename which one is fastest? |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Quote:
Observe... Code:
$ cat > flatfile 1st line 2nd line 3rd line ^D $ sed -i '1d' flatfile $ more flatfile 2nd line 3rd line Cheers ZB |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
perl -pi -e '$_ = "" if ($. == 1);' filename
works very well. Thanks very much for your help, Tanku and Reborg. Regards, xli |
| Sponsored Links | ||
|
![]() |
| Tags |
| sed delete line, shell script, shell scripting, unix commands, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove numeric characters in the flat file | rafimd1985 | UNIX for Dummies Questions & Answers | 4 | 03-03-2012 11:02 PM |
| Remove the footer from a flat file by searching a pattern | gani_85 | Shell Programming and Scripting | 6 | 10-03-2011 02:05 AM |
| Remove somewhat Duplicate records from a flat file | jolney | Shell Programming and Scripting | 4 | 09-29-2011 04:01 PM |
| remove specific lines from flat file using perl | meghana | Shell Programming and Scripting | 12 | 02-12-2008 08:50 PM |
| How to remove page breaks from a flat file??? | kumarsaravana_s | Shell Programming and Scripting | 5 | 04-17-2007 08:51 AM |
|
|