Replace whole lines in the file from different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace whole lines in the file from different files
# 8  
Old 04-14-2009
here is the code

Here is the code from notepad++.
Windows-based editor create a problem?

file2.txt
Code:
  101  606       20.       15.        1.        1.       0.1      0.12        0.
  101  606      1.2.       25.        3.      0.5.       0.5      0.22        0.

file3.txt
Code:
  101  606       0.2     1.376       0.1      0.25       0.1       1.1 
  101  606        1.     12.76       3.1       1.0       1.1       2.1

shell script
Code:
#----------------------------------------------------------------------#
# Internal field separator to pipe.                                    #
#----------------------------------------------------------------------#
IFS="|"
#----------------------------------------------------------------------#
# Counter for file name.                                               #
#----------------------------------------------------------------------#
num=1
#----------------------------------------------------------------------#
# Paste parameter files together with pipe symbol.                     #
#----------------------------------------------------------------------#
paste -d\| file2.txt file3.txt |while read a b ; do
#----------------------------------------------------------------------#
# Create numbered configuration files.                                 #
#----------------------------------------------------------------------#
  cat << EOF > file$num.conf
PWAT-PARM1
*** < PLS> PETMAX PETMIN INFEXP INFILD DEEPFR BASETP AGWETP
*** x - x (deg F) (deg F)
$a
END PWAT-PARM1

PWAT-PARM2
*** <PLS > CEPSC UZSN NSUR INTFW IRC LZETP
*** x - x (in) (in) (1/day)
$b
END PWAT-PARM2
EOF

#----------------------------------------------------------------------#
# Next number...                                                       #
#----------------------------------------------------------------------#
  (( num += 1 ))
done

# 9  
Old 04-15-2009
it might have been the editor. but i did forget the first line. on my system
the default shell is /bin/ksh.... so for you....

add:

Code:
#!/bin/ksh

to the very first line.

vi the file in unix and verify that no CONTROL-M's show up.

also try changing:

Code:
(( num += 1 ))

to:
Code:
$(( num = num + 1 ))

everything else should be fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace lines of two files by the corresponding line numbers.

I want to replace lines. The files 1 are (separated by \t) Gm01 phytozome9_0 three_prime_UTR 70641 70759 . - . ID=PAC:26323927.three_prime_UTR.1;Parent=PAC:26323927;pacid=26323927 Gm01 phytozome9_0 three_prime_UTR 90230 90692 . - . ... (1 Reply)
Discussion started by: grace_shen
1 Replies

2. UNIX for Advanced & Expert Users

SQL script with 86000 lines: new files with only 10000 lines (per file)

Hi this is my SQL script $ wc -l insert_into_customers.sql 85601 insert_into_customers.sqlI wish to cut this file into 9 files each 10000 lines (the last one less) $ wc -l insert_into_customers_00*.sql 10000 insert_into_customers_001.sql 10000 insert_into_customers_002.sql ... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

3. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

4. Shell Programming and Scripting

perl or sed replace lines only if for all files

Hi Everyone, # cat 3 a b # cat 4 a b # perl -p -i -e "s/.*/c/ if $.==2" * # cat 3 a c # cat 4 a b (4 Replies)
Discussion started by: jimmy_y
4 Replies

5. Shell Programming and Scripting

Replace lines in a file

Hi everybody, I am a newbie in shell scripting and I'm trying to write a script which reads lines from a file, searching some of this lines to change a specified number. I want to replace the line for another in the file. I have to replace multiples lines, so I have a for. Now I am trying with... (1 Reply)
Discussion started by: alex82
1 Replies

6. Shell Programming and Scripting

Replace lines from one file to another

Hello, I have 8 lines containing these unique words in both files 645147468537 673962863160 673962864957 691717701950 707917019907 790085591726 792975507744 852174812753 file.dat.orig (has 1000 lines) and file.dat(has only 8 lines) I want to replace those lines in file.dat.orig by... (1 Reply)
Discussion started by: jakSun8
1 Replies

7. Shell Programming and Scripting

find and replace three lines in files?

Hello, i usually use this for one tag or line: find . -type f -exec replace "whatever goes here" "" -- {} \; but i want to replace three lines in a file for example this: <script language=javascript>< ... (1 Reply)
Discussion started by: Bashar
1 Replies

8. Shell Programming and Scripting

replace lines in a file

I've got a file full of numbers, example: cat test.file 60835287 0 51758036 40242437 0 32737144 0 24179513 0 4131489957 I want to replace those numbers (4 Replies)
Discussion started by: TehOne
4 Replies

9. Shell Programming and Scripting

replace multiple lines in file

Hello I am a beginner in shell script. I was trying to find a way to replace multiple lines of a file with different set of multiple line. sed -n '/begin/,/end/p' < sample1.txt >test.txt UNEDITED=`cat test.txt` vi test.txt EDITED=`cat test.txt`... (2 Replies)
Discussion started by: nox
2 Replies

10. Shell Programming and Scripting

How can I replace multiple lines from different files

Suppose i have two files file1.txt Name : Raju Address:rt8pouououoiu City:tyretyeuetu file2.txt Address :28a The line "address:28a" in file2 has to get replaced in the address line of file1 .. The output should be Name :Raju Address:28a city :tyretyeuetu Please help me... (2 Replies)
Discussion started by: ranga27
2 Replies
Login or Register to Ask a Question