script to add first line from another file in aix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to add first line from another file in aix
# 1  
Old 03-04-2008
PHP script to add first line from another file in aix

Hi All,

I want to add a header from one file to another file which is around 2GB in size currently i am using cat to do it. It took more time to process. Is there any way to do it? Please help me ..

Thanks in Advance

Selva S
# 2  
Old 03-04-2008
Hi selva,

I hope the below will work for you,

head -1 input_file > output_file
# 3  
Old 03-04-2008
Quote:
Originally Posted by apsprabhu
Hi selva,

I hope the below will work for you,

head -1 input_file > output_file

It will replace my original file Smilie
If i used >> instead of > it will also append


I want to write first line of old file from a text file.

I am using below one at present

cat singlelinefile > newfile
cat millionlinefile >>newfile
mv millionlinefile millionlinefile.old
mv newfile millionlinefile
# 4  
Old 03-04-2008
Hi,

i assume you want to take the hearder fom file1 and append it as header of file2. then below script will work for you,

head -1 file1> temp_file
cat temp_file file2 >output_file


Now the header of file1 and contents of file2 are written into new file called "output_file".

If you want to move the new output_file to old name itself means,
mv output_file >file2 (old_file)
# 5  
Old 03-04-2008
Code:
# sed script to insert "header.txt" above the first line
1{h; r header.txt
  D; }
2{x; G; }
#---end of sed script---

Code:
cat header.txt
HEADER

Code:
cat file1
INSERT HERE
jkqfqjkdf
qsdjfhqskfh
qjsdhfqsjkf
qjsdhflqjf

Code:
sed -f script file > file2
cat file2
HEADER
INSERT HERE
jkqfqjkdf
qsdjfhqskfh
qjsdhfqsjkf
qjsdhflqjf

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

2. Shell Programming and Scripting

How to add a line in a file using perl script?

Hi all, I want to search for a line in a file using perl script and add a line above that line.Can any one suggest me command or code to that using script. Thanks BHarath (5 Replies)
Discussion started by: bharathece
5 Replies

3. Shell Programming and Scripting

Script to loop line in a file and add info or do echo

I have a record.txt it will update weekly, and it could be 2 lines or more ... it just echo each line to the script san jose,23.34% tampa,2.15% dallas,30.20% seattle,44.29% Unknown,16.72% How do i write a shell script to give me a test.pl or bash file which contain #!/home/perl... (8 Replies)
Discussion started by: sabercats
8 Replies

4. UNIX for Advanced & Expert Users

How to take file line count in AIX

HI All, I am trying to take file line count in UNIX and AIX Unix command to take file line count-- working fine count=`wc -l /apps/hgford/sorted/E.testing.DLY|cut -f1 -d " "` 1355Same command when run in aix --having issue count=`wc -l /apps/hgford/sorted/E.testing.DLY|cut -f1 -d " "`... (5 Replies)
Discussion started by: Perlbaby
5 Replies

5. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

6. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

7. Shell Programming and Scripting

Need awk script to add a prefix to each line in file

Hello , I have file with below content : '165567885', '165568443', '165568805', I need an awk script that would add a prefix zero after first ' . Like '0165567885', '0165568443', '0165568805', Please help. Thanks in advance. (5 Replies)
Discussion started by: rmv
5 Replies

8. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

9. Shell Programming and Scripting

perl script to add a line into a file

hi all need a perl script to add a line into a file thanks with anticipation (2 Replies)
Discussion started by: karthikn7974
2 Replies

10. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies
Login or Register to Ask a Question