Sponsored Content
Top Forums UNIX for Advanced & Expert Users replacing first line or lines in a file Post 302077286 by blowtorch on Wednesday 21st of June 2006 03:40:48 AM
Old 06-21-2006
Are you looking for something like this:
Code:
# cat test
this is line 1
this is line 2
this is line 3
# sed '1s/this is line/that is line/' test
that is line 1
this is line 2
this is line 3
# sed '2s/this is line/that is line/' test
this is line 1
that is line 2
this is line 3

Members may be able to help you better if you posted a part of the file you are working with and exactly what you are trying to do with the file.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing specific lines in a file

Hi there I have a file which has the lines # Serial number for hostid EXP_SERIAL_="" These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with # Serial number for hostid $var1 EXP_SERIAL_$var1="$var2" Is there a quick and simple... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

2. Shell Programming and Scripting

replacing multiple lines with single line

Can any one give me the idea on replacing multiple blank lines with a single blank line? Please conside it for a file having more than 100 number of characters. Regards, Siba (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

3. Shell Programming and Scripting

Replacing Block of lines in a text file

Dear All, Regards of the Day. I have a text file with some functions: Function1 { parameter 1 parameter 2 parameter 3 } end Function2 { parameter 1 parameter 2 parameter 3 } (1 Reply)
Discussion started by: ashisharora
1 Replies

4. Shell Programming and Scripting

Replacing line 'i' of file1 with line 'j' of file 2

Hi All, As mentioned in the title I have two text files and I would like to replace line number 5 of file #1 with line number 4 of file #2 e.g. file 1 wqwert 4.4464002 3 319 286 369 46.320002 56.150002 45.100002 1 1 1 0.723 (12 Replies)
Discussion started by: f_o_555
12 Replies

5. Shell Programming and Scripting

replacing multi lines with 1 line

I have an xml file that is stripped down to output that looks bacically like; <!-- TABLEA header --> <tablea> some fields </tablea> <!-- TABLEB header --> <!-- TABLEC header --> <tablec> some fields </tablec> I want to remove the header... (3 Replies)
Discussion started by: Griffs_Revenge
3 Replies

6. UNIX for Dummies Questions & Answers

Replacing 2 lines by single line

Hi I have a file with below content : a b S I need to replace the lines which have a and b continuously by d. d S I have used the below code tr '\n' '#'<file|sed. 's/a#b/d/g's?|tr '#' '\n' where # is not occurring anywhere in the file.. Is there any other efficient way to do this? ... (7 Replies)
Discussion started by: pandeesh
7 Replies

7. Shell Programming and Scripting

Replacing a single line with multiple lines in a file

Hi Am confused with the usage of "sed" command I want to replace a single line with multiple lines of a file.. eg., A file has Hi, How are you? I need to replace as Am fine What are You doing? I used the script as string1="Hi, How are you?" echo "$string1 is the value"... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

8. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

9. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

10. Shell Programming and Scripting

Matching and Replacing file lines starting with $

Here is the task that I was presented with: I am dealing with about a 10,000 line input deck file for an analysis. About 10 separate blocks of around 25 lines of code each need to be updated in the input deck. The input deck (deckToChange in the code below) comes with 2 separate files. File 1... (5 Replies)
Discussion started by: tiktak292
5 Replies
SUBST(1)						      General Commands Manual							  SUBST(1)

NAME
subst - substitute definitions into file(s) SYNOPSIS
subst [ -e editor ] -f substitutions victim ... DESCRIPTION
Subst makes substitutions into files, in a way that is suitable for customizing software to local conditions. Each victim file is altered according to the contents of the substitutions file. The substitutions file contains one line per substitution. A line consists of two fields separated by one or more tabs. The first field is the name of the substitution, the second is the value. Neither should contain the character `#', and use of text-editor metacharacters like `&' and `' is also unwise; the name in particular is best restricted to be alphanumeric. A line starting with `#' is a comment and is ignored. In the victims, each line on which a substitution is to be made (a target line) must be preceded by a prototype line. The prototype line should be delimited in such a way that it will be taken as a comment by whatever program processes the file later. The prototype line must contain a ``prototype'' of the target line bracketed by `=()<' and `>()='; everything else on the prototype line is ignored. Subst extracts the prototype, changes all instances of substitution names bracketed by `@<' and `>@' to their values, and then replaces the tar- get line with the result. OPTIONS
-e Substitutions are done using the sed(1) editor, which must be found in either the /bin or /usr/bin directories. To specify a dif- ferent executable, use the ``-e'' flag. EXAMPLE
If the substitutions file is FIRST 111 SECOND 222 and the victim file is x = 2; /* =()<y = @<FIRST>@ + @<SECOND>@;>()= */ y = 88 + 99; z = 5; then ``subst -f substitutions victim'' changes victim to: x = 2; /* =()<y = @<FIRST>@ + @<SECOND>@;>()= */ y = 111 + 222; z = 5; FILES
victimdir/substtmp.new new version being built victimdir/substtmp.old old version during renaming SEE ALSO
sed(1) DIAGNOSTICS
Complains and halts if it is unable to create its temporary files or if they already exist. HISTORY
Written at U of Toronto by Henry Spencer. Rich $alz added the ``-e'' flag July, 1991. BUGS
When creating a file to be substed, it's easy to forget to insert a dummy target line after a prototype line; if you forget, subst ends up deleting whichever line did in fact follow the prototype line. 25 Feb 1990 SUBST(1)
All times are GMT -4. The time now is 12:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy