Computing.Net > Forums > Unix > Copy a part of a file up to specifi

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.

Copy a part of a file up to specifi

Reply to Message Icon

Name: eugeneMerlin
Date: April 16, 2008 at 11:08:58 Pacific
OS: UNIX
CPU/Ram: -
Product: -
Comment:

Hi. I have a file "file1.txt". It contains the line "End Of Copy" in the middle. I need to copy all the lines ABOVE that line into "file2.txt" . I.e. if "file1" is

Line 1
Line 2
"End Of Copy"
Line 3
Line 4
Line 5

i need to have in "file2" only

Line 1
Line 2

Thank you!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: April 16, 2008 at 14:40:37 Pacific
Reply:



#!/bin/ksh

rm -f file2
while read line
do
if [[ "$line" == "\"End Of Copy\"" ]]
then
break
fi
echo "$line" >> file2
done < file1



0

Response Number 2
Name: ghostdog
Date: April 16, 2008 at 19:19:07 Pacific
Reply:


awk '/End Of Copy/{exit}1' file


0

Response Number 3
Name: eugeneMerlin
Date: April 18, 2008 at 10:34:41 Pacific
Reply:

Gentlemen,

Thank you very, very much.


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: Copy a part of a file up to specifi

Extracting a part of text using AWK www.computing.net/answers/unix/extracting-a-part-of-text-using-awk/7776.html

prevent a file from being removed.. www.computing.net/answers/unix/prevent-a-file-from-being-removed/4884.html

to split a file www.computing.net/answers/unix/to-split-a-file/5481.html