appending a file using sed in ksh

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting appending a file using sed in ksh
# 1  
Old 01-02-2008
Question appending a file using sed in ksh

i am trying to append a 5 line SGML file(file1) with a 500,000 line SGML file (file2).

file1 is a template, so i wish to preserve.
i only want to add lines 5 to the end of file2.

i have:
cp file1 temp1
sed -n '5,$p' file2 >> temp1

when i check the tail of temp1, i consistantly find the last 4 lines missing.

i have run a line count on file2 and inserted in sed -n '5,500000p' with same result.

please note, filepaths are absolute because the script runs from a seperate script folder.

can someone help?
# 2  
Old 01-02-2008
It's not clear if you want to prepend or append, but one of these should do it:

cat extra file1 > file2
cat file1 extra > file2

extra is file with the 5 new lines.
# 3  
Old 01-02-2008
thanks for replying Perderabo, but i was probably not clear.

file one actually has 7 lines. i want to replace the first 4 lines of file2 with file1.

so i copied file1 to temp1 (new file), then tried to append the new file with lines 5 thru 548203 of file2.

everything works except that i am always missing lines 548200 to 5482003 in the new file.

i do not know how to extract lines 5 thru 548203 using cat. also, because the line count is a variable i'd prefer to not use head | tail.
# 4  
Old 01-02-2008
nevermind...figured it out. thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed command help (appending)

I need to append a user to the end of a group in the /etc/group file ftp::49:user1,user2... what I want to to add a new user to the group file so that I won't have to open it up and append manually and I can't user "usermod" it fails this user will be coming from a variable (11 Replies)
Discussion started by: slufoot80
11 Replies

2. Shell Programming and Scripting

sed appending problem

i have a number of java files containing eg: package; import java.* import something..; import sdfdfdsa; ... ... -------------------------------------------- Now I need to append / insert a line as follows: ... (10 Replies)
Discussion started by: linuxadmin
10 Replies

3. UNIX for Dummies Questions & Answers

sed - appending text

Hey all I am trying to append a file called datebook.txt. I want to append the end of each line containing the name Fred with three ***. I believe I need to make the * loose its meta character meaning in addition to using the append command. I have tried several variations of this command and I... (3 Replies)
Discussion started by: citizencro
3 Replies

4. Shell Programming and Scripting

Awk/Sed - appending within file

hello all, First time post here. I have searched a bit but could not find an exact answer. I have about a week's experience of Sed and Awk, and am having fun, but am a little stuck. I am reformatting an xml file into json format. I have got this far: {"clients": ...and so on. What I want... (22 Replies)
Discussion started by: singerfc
22 Replies

5. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

6. Shell Programming and Scripting

awk/sed/ksh script to cleanup /etc/group file

Many of my servers' /etc/group file have many userid's that does not exist in /etc/passwd file and they need to be deleted. This happened due to manual manipulation of /etc/passwd files. I need to do this for 40 servers. Can anyone help me in achieving this? Even reducing a step or two will be... (6 Replies)
Discussion started by: pdtak
6 Replies

7. Shell Programming and Scripting

appending and sed

Hello, I want to add string #REAL at the end of all lines that contain real numbers. How to do this using sed ? (1 Reply)
Discussion started by: scotty_123
1 Replies

8. Shell Programming and Scripting

appending to sed output of one file into the middle of file

hi, i have a file file1 file2 ----------- ----------------- aa bbb ccc 111 1111 1111 ddd eee fff 222 3333 4444 ggg hhh... (5 Replies)
Discussion started by: go4desperado
5 Replies

9. Shell Programming and Scripting

Appending string to xml file using "sed"

Hi folks, Following a section in opmn.xml file: </process-type> <process-type id="OC4J_RiGHTv_IRD1" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (2 Replies)
Discussion started by: nir_s
2 Replies

10. UNIX for Dummies Questions & Answers

SED Question -- on appending to a file

:confused: I have a script that Cats a flat database file which contains 12 columns into sed. I want to add a 13th column which includes " ,2005-08-29 " * The date needs to be the current date. This 13th column would be appended to the end of each line. Does anyone have a clue... (5 Replies)
Discussion started by: Redg
5 Replies
Login or Register to Ask a Question