![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed remove last 10 characters of a line start from 3rd line | minifish | Shell Programming and Scripting | 7 | 03-26-2008 01:42 PM |
| SED help (remove line::parse again::add line) | Malumake | Shell Programming and Scripting | 6 | 10-24-2007 02:02 PM |
| Remove header(first line) and trailer(last line) in ANY given file | madhunk | Shell Programming and Scripting | 2 | 03-13-2006 12:36 PM |
| Remove first 15 line | bobo | UNIX for Dummies Questions & Answers | 6 | 01-30-2006 06:26 PM |
| To remove new line character | shihabvk | UNIX for Advanced & Expert Users | 6 | 08-18-2005 12:02 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
remove the first line of all files
I want to remove the first line of all files in a directory with .dat extension. Can any one help me on this with a small script. I want the file names to remain same .
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
ls *dat|xargs -i ksh -c 'sed -e "1d" {}>{}.tmp;mv {}.tmp {}'
|
|
#3
|
|||
|
|||
|
it gives an error
stty: : No such device or address
|
|
#4
|
|||
|
|||
|
Quote:
Code:
# tail +2 file.dat > newfile Code:
# more +2 file.dat > newfile |
|
#5
|
||||
|
||||
|
Just for fun:
Code:
awk 'FNR != 1 { print >>FILENAME".tmp";next}
{ print FILENAME
">"FILENAME".tmp" }' *dat|xargs -i mv "{}.tmp" "{}"
|
|
#6
|
|||
|
|||
|
for files in `ls *.dat` #list of all .dat file
do cp $files $files.bck #make a backup of the file sed '1d' -i $files #remove the first line of the file done Rakesh UV Last edited by uvrakesh; 01-04-2008 at 04:52 AM. Reason: the comment were to near making it look more unclear |
|
#7
|
|||
|
|||
|
just for fun: for very large files, use awk/more instead of sed '1d' method.
Code:
# wc -l file1 8998841 file1 # time sed '1d' file1 > sedtest real 0m28.329s user 0m26.930s sys 0m1.000s # time sed -n '2,$p' file1 > sedtest real 0m33.740s user 0m29.842s sys 0m1.096s # time more +2 file1 > moretest real 0m10.629s user 0m8.353s sys 0m0.856s # time awk 'NR>1' file1 > awktest real 0m14.618s user 0m7.476s sys 0m1.016s |
|||
| Google The UNIX and Linux Forums |