Inserting lines in between the contents of file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting lines in between the contents of file.
# 1  
Old 10-20-2008
Inserting lines in between the contents of file.

Hi,

I want to insert some lines in between the contents of a file but the file format should not be changed.

#!/usr/bin/sh -
# Link appropriate OS specific versions of vxicap and vxchk4badblks
vxlvmlink()
{
vxipath=/usr/lib/vxvm/bin
relmajor=`uname -v`
relminor=`uname -r`

if [ $relmajor -ne 5 ]; then
ewritemsg -s ERROR -n vxlvmlink "vxlvmlink() works only for 5.1 <= AIX <= 5.3\n"
return 255
fi
}
PATH=/usr/lib/vxvm/bin:/sbin:/usr/sbin:/usr/bin

vxddladm excludearray all; vxdctl enable
vxddladm includearray all; vxdctl enable


# Retry connecting vold for 1 minute, fail otherwise
__VXVM_RETRY_SET="yes"
export __VXVM_RETRY_SET

I have to include the lines in blue color in between in the same place.
I don't want to change the format of file as it spoil all the alignment of code hence not interest to add the line using while read line.
Any other way to include the lines in between the files guys?

Regards,
Ajilesh
# 2  
Old 10-22-2008
Something like this:

Code:
cp -p /tmp/sourcefile /tmp/sourcefile.orig
sed '/Retry connecting/i\
vxddladm excludearray all; vxdctl enable\
vxddladm includearray all; vxdctl enable\
' /tmp/sourcefile.orig > /tmp/sourcefile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk function to remove lines that contain contents of another file

Hi, I'd be grateful for your help with the following. I have a file (file.txt) with 10 columns and about half a million lines, which in simplified form looks like this: ID Col1 Col2 Col3.... a 4 2 8 b 5 6 1 c 8 4 1 d... (4 Replies)
Discussion started by: aberg
4 Replies

2. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

3. Shell Programming and Scripting

Inserting lines from one file to a sorted list

Hello friends! I am working a Psychology/Neuro* project where I am sorting inline citations by category. The final step of the process has me a little stuck. I need to take citations from a text list and sort them in another text file. Here is a file X example... (1 Reply)
Discussion started by: danbroz
1 Replies

4. UNIX for Advanced & Expert Users

Inserting duplicate lines in a file

Hi, I copied the contents of a binary file into a .text file using hd (hexdump) command. The data in binary file is such that I get in many places like following 00000250 00 00 00 00 3f 2d 91 68 3f 69 fb e7 00 00 00 00 |....?-.h?i......| 00000260 00 00 00 00 00 00 00 00 00 00 00 00 00... (2 Replies)
Discussion started by: KidD312
2 Replies

5. UNIX for Dummies Questions & Answers

find lines in another file based on contents in a second file

Hello, I have a file with tab delimited columns like: File1 A 2 C R F 4 D Q C 9 A B ...... I want to grep out the lines in a second file, File2, corresponding to each line in File1 Can I do this: while read a b c d do grep '$a\t$b\t$c\t$d' File2 >>... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

6. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

7. Shell Programming and Scripting

Read file contents and separate the lines when completes with =

Hi, I have a file like this cpsSystemNotifyTrap='2010/12/14 11:05:31 CST' Manufacturer=IBM ReportingMTMS=n/a ProbNm=26 LparName=n/a FailingEnclosureMTMS=7946-IQL*99G4874 SRC=B3031107 EventText=Problem reported by customer. CallHome=true Calendar I want to have a output like this... (6 Replies)
Discussion started by: dbashyam
6 Replies

8. Shell Programming and Scripting

Remove lines based on contents of another file

So, this issue is driving me nuts! I was hoping to get a lending hand here... I have 2 files: file1.txt contains: this is example1 this is example2 this is example3 this is example4 this is example5 file2.txt contains: example3 example5 Basically, I need a script or command to... (4 Replies)
Discussion started by: bashshadow1979
4 Replies

9. Shell Programming and Scripting

inserting a lines in a file

Hi folks, i need to insert the same set of lines between each line input lines 111111 aaaaaa 333333 output should be 111111 1 2 3 aaaaaa 1 2 3 333333 1 (2 Replies)
Discussion started by: Balaji Sukumara
2 Replies

10. Shell Programming and Scripting

put the contents of this file into a variable with multiple lines

I have a file that contains the following lines the brown quick fox jumped over the white laze dog 0123456789 I wanted to put the contents of this file into a variable so I used this code: VAR_LIST=`cat $2` where $2 is the file name passed as an argument to the script If I... (3 Replies)
Discussion started by: Nomaad
3 Replies
Login or Register to Ask a Question