I have two questions. First, I was wondering how to use sed to remove two header lines or two tail lines. Here I just do the same operation twice...I'm sure there is a better way. Second, and more importantly, is there a better way to have these operations use files other than having it output these dumb ZZ* files and then rm them? There must be a more elegant way...
I'm not the sed expert, so removing the last two lines is beyond me. Removing the first two lines in one command is pretty straight forward:
1,2d reads: delete the range of lines 1 through 2.
To do everything you want in one swoop, I'd turn to awk:
You can smash it all onto one line if you want; easier to read this way I think.
It ditches all lines before line three, then buffers two lines such that the last two lines of the input are never printed.
If you want to replace your original input file, you will have to write the output to a temporary file, and them move the temp file back to the original file name. No way of getting round this, and it does prevent disaster as you can check for errors etc. before renaming the output and trashing the input file.
To answer your other question, you could have piped your commands together to not have to deal with the temp files:
I didn't test that, so with luck I've not introduced any typos.
Last edited by agama; 08-25-2010 at 12:35 AM..
Reason: added comments
I have a file called "dsout" with empty rows and duplicate headers.
DATE TIME TOTAL_GB USED_GB %USED
--------- -------- ---------- ---------- ----------
03/05/013 12:34 PM 3151.24316 2331.56653 73.988785 ... (3 Replies)
Good evening
I need your help please, im new at Unix and i wanted to remove the first 5 headers for 100000 records files and then create a control file .ctl that contains the number of records and all seem to work out but when i tested at production it didnt wotk.
Here is the code:
#!... (6 Replies)
Good evening
Im new at unix shell scripting and im planning to script a shell that removes headers for about 120 files in a directory and each file contains about 200000
lines in average.
i know i will loop files to process each one and ive found in this great forum different solutions... (5 Replies)
Hi,
I have catenated multiple output files (from a monte carlo run) into one big output file. Each individual file has it's own two line header. So when I catenate, there are multiple two line headers (of the same wording) within the big file. How do I use the sed command to search for the... (1 Reply)
Heya there,
A small selection of my data is shown below.
DATE TIME FRAC_DAYS_SINCE_JAN1
2011-06-25 08:03:20.000 175.33564815
2011-06-25 08:03:25.000 175.33570602
2011-06-25 ... (4 Replies)
Hi,
I'm trying to strip all lines between two headers in a file:
### BEGIN ###
Text to remove, contains all kinds of characters
...
Antispyware-Downloadserver.com (Germany)=http://www.antispyware-downloadserver.c
om/updates/
Antispyware-Downloadserver.com #2... (3 Replies)
Hello,
So i want to send mails in any way from a solaris 5.8 system, perhaps using mailx or sendmail. My purpose is to stay clear of systems name in head data. So i want to strip at least the "Message-Id" and the "Recieved" headers of the mail. Yet this seems to be a bit of a problem.
Now i... (2 Replies)
Hi All,
Following is the part of my script.It does contain many for loops and is not elegant. Please feel free to suggest any changes to make this elegant.
Thanks!
nua7
for i in `ls $CATALINA_HOME/shared/lib/*.jar`;
do
LOCALCLASSPATH="$LOCALCLASSPATH:$i"
done
for i in... (3 Replies)
I have a data file with over 500,000 records/lines that has the header throughout the file.
SEQ_ID Name Start_Date Ins_date Add1 Add2
1 Harris 04/02/08 03/02/08 333 Main Suite 101
2 Smith 02/03/08 01/23/08 287 Jenkins
SEQ_ID Name ... (3 Replies)
Hi
I am running a script (which compares two directory contents) for which I am getting an output of 70 pages in which few pages are blank so I was able to delete those blank lines.
But I also want to delete the headers present for each page. can any one help me by providing the code... (1 Reply)