Sponsored Content
Full Discussion: Replace last n lines
Top Forums Shell Programming and Scripting Replace last n lines Post 303028037 by onenessboy on Sunday 30th of December 2018 06:35:34 AM
Old 12-30-2018
Quote:
Originally Posted by RavinderSingh13
Hello onenessboy,

Could you please try following once.

Code:
tac Input_file | awk 'FNR==2{sub("static","dynamic")} FNR==3{sub("gnutls","ls")} 1' | tac

In case you want to save output into Input_file itself then append > temp_file && mv temp_file Input_file in above code too.

Thanks,
R. Singh
Hi Ravinder,

Thanks much for help, but is there any way that we can replace nth line without any conditions to check ? as your solution checking for strings and then replace, but is there any way, I can directly remove last but two lines and replace entire line as per my previous post ? what I mean remove completely last but two line before in that input file and append/replace these two lines in that place. The reason being stlib value may contain another strings also at times so wanted to remove that line and append
Code:
stlib='smb_dynamic bsd z resolv rt',
lib='dl ls'


Last edited by onenessboy; 12-30-2018 at 07:46 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED - Search and replace lines containing...

Hi, I need a sed line that will find all lines that contain "<int key="NSWindowStyleMask">" and then replace the entire line (not just that one string) with "<int key="NSWindowStyleMask">8223</int>". It doesn't necessarily have to use sed as long as it gets the job done :) Thanks (9 Replies)
Discussion started by: pcwiz
9 Replies

2. 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

3. Shell Programming and Scripting

sed to replace two lines with one

I want to use sed to check if a short line is contained in the line after it, and if it is, to delete the short one. In other words, the input is... This is a This is a line ... and I want it to give me... This is a line Here's what I've tried so far: s/\(^.*\)\n\(\1.*$\)/\2/ Also,... (7 Replies)
Discussion started by: estebandido
7 Replies

4. 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

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

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

7. Shell Programming and Scripting

Find and Replace Different Lines

Hi, I am looking at modifiying a file but getting a bit lost with what i am trying to do. I have the following file i need to alter. I want to search a list of files for the DEVSERIAL "0007862454" part but only the numbers. I then need to replace the line under DRIVES with the correct drive... (7 Replies)
Discussion started by: forcefullpower
7 Replies

8. Shell Programming and Scripting

[sed] Replace one line with two lines

Literally cannot get this one, guys. Single line replacement is simple, but I am not understanding the correct syntax for including a new line feed into the substitution part. Here's what I got. (Cannot use perl) #!/bin/sh set -f #Start Perms export HOME=/home/test_user # End Perms... (6 Replies)
Discussion started by: Parallax
6 Replies

9. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

10. UNIX for Dummies Questions & Answers

Replace character in odd or even lines

Hello, I'm here again asking for your precious help. I'm writing some code to convert csv files to html. I want to highlight header and also I want to have rows with alternate colors. So far this is my work###Let's format first line only with some color cat $fileIN".tmp1" | sed '1... (7 Replies)
Discussion started by: emare
7 Replies
REPLACE(1)						       MySQL Database System							REPLACE(1)

NAME
replace - a string-replacement utility SYNOPSIS
replace arguments DESCRIPTION
The replace utility program changes strings in place in files or on the standard input. Invoke replace in one of the following ways: shell> replace from to [from to] ... -- file_name [file_name] ... shell> replace from to [from to] ... < file_name from represents a string to look for and to represents its replacement. There can be one or more pairs of strings. Use the -- option to indicate where the string-replacement list ends and the file names begin. In this case, any file named on the command line is modified in place, so you may want to make a copy of the original before converting it. replace prints a message indicating which of the input files it actually modifies. If the -- option is not given, replace reads the standard input and writes to the standard output. replace uses a finite state machine to match longer strings first. It can be used to swap strings. For example, the following command swaps a and b in the given files, file1 and file2: shell> replace a b b a -- file1 file2 ... The replace program is used by msql2mysql. See msql2mysql(1). replace supports the following options. o -?, -I Display a help message and exit. o -#debug_options Enable debugging. o -s Silent mode. Print less information what the program does. o -v Verbose mode. Print more information about what the program does. o -V Display version information and exit. COPYRIGHT
Copyright (C) 1997, 2014, Oracle and/or its affiliates. All rights reserved. This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/. SEE ALSO
For more information, please refer to the MySQL Reference Manual, which may already be installed locally and which is also available online at http://dev.mysql.com/doc/. AUTHOR
Oracle Corporation (http://dev.mysql.com/). MySQL 5.5 01/30/2014 REPLACE(1)
All times are GMT -4. The time now is 10:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy