Computing.Net > Forums > Unix > Cat Start & End of File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Cat Start & End of File

Reply to Message Icon

Name: hismail
Date: June 13, 2005 at 02:25:14 Pacific
OS: Sco Openserver
CPU/Ram: Dual processor/2 gig
Comment:

Hi
Is there anyway of doing a "cat" of the start & end of a file & append it to another
eg:
__Start file______
00:00 this is the start........
.
.
.
04:00 this is the end..
---end of file-------------
I need to put the start & end times of a log file to another file

Any help will be appreciated thanks
Hamim



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: June 13, 2005 at 04:12:52 Pacific
Reply:

head -1 > newfile
tail -1 >> newfile

man head
man tail


0

Response Number 2
Name: hismail
Date: June 15, 2005 at 02:15:01 Pacific
Reply:

Hi

Thanks For your Help, I managed to get the out of the file but cannot get the home directory inside the contents of my file called HOME.
any ideas??

LOG=`find . -name day0*.log -mtime +1 \ `
STARTFILE=`head -6 $LOG >/tmp/HOME`
ENDFILE=`tail -l |grep Logfile $LOG>>/tmp/HOME`
for dir in $HOME;do echo $HOME;done

it only echo the home directory to screen?



0

Response Number 3
Name: David Perry
Date: June 17, 2005 at 12:42:05 Pacific
Reply:

Would you post a sample of your data file?

Where is $HOME being created?


0

Response Number 4
Name: hismail
Date: June 19, 2005 at 23:41:49 Pacific
Reply:

My Previuos script does not give me the latest file created ie day*.log
I tried this ,but it cannot find the first variable as it has to do a find inside the home directories.
I am starting my script from /home;

Here is my script:
#!/bin/ksh
LOG=`ls -lt day*.log|grep "^-" |head -1 |awk '{print $NF}'`
STARTFILE=`head -6 $LOG >/tmp/HOME`
ENDFILE=`tail -l |grep Logfile $LOG>>/tmp/HOME`
for f in $(find /home/sing* -type f -name $LOG);do
cd $(dirname $f);$STARTFILE;$ENDFILE;cd -
done

I get an error cannot find day*.log-
How can I get my script to ignore $LOG & then use it again after the find.

Thanks David


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Cat Start & End of File

sed dropping last line of file www.computing.net/answers/unix/sed-dropping-last-line-of-file/5125.html

Append to last line of file www.computing.net/answers/unix/append-to-last-line-of-file/5212.html

How to collect the files www.computing.net/answers/unix/how-to-collect-the-files/4840.html