Hi All,
I am karthik. I am new to this forum. I have one requirement.
I have a file with header and footer.
Header may be like
HDR0001
or
FILE20090110
(Assume it is unknown so far, but i am sure there is a header in the file)
likewise file has the trailer too.
I just want to remove the header & footer and BCP data into a table.
Note: The file size would be 1.5 GB to 2.0 GB.
So i am looking for some good way to remove the header and trailer.
Inputs are welcome!
This should do the trick:
awk 'NR<3{s=$0;next}{print s;s=$0}' file > newfile
or:
sed '1d;$d' file > newfile
Thanks Franklin!
I tested the second one. It works fine.
But i don't want to create another file. I tested the script as below
filename > filename. After executing the script, the <filename> becomes empty.
so isn't possible to remove the header & footer and store it in the same file itself?
Also can you tell me what is the difference between the first one and second one? i mean which will give give good performance?
awk 'NR<3{s=$0;next}{print s;s=$0}' file > newfile
Explanation of awk code:
NR<3{s=$0;next}
If line number < 3 assign the current line to variable s and read the next line
{print s;s=$0}
Print the previous line and assign the current line to variable s
Explanation of sed code:
sed '1d;$d'
Delete the first (1d) and the last line ($d)
Answer for one of your question:
How to make the edit in the same file itself,
use -i switch in sed as
sed -i <REQUIRED-PART>
sed: illegal option -- i
$
i got the above error message.
i am using ksh.
is there any other option to do this?
No, but you can do something like:
sed '1d;$d' file > tempfile && mv tempfile file
binlib
8
Check the -F and -L command line options of bcp.