Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Change Specific Line of a File Post 302226305 by jim mcnamara on Monday 18th of August 2008 04:41:53 PM
Old 08-18-2008
Code:
different_text="this is the new text"
awk -v diff="$different_text" '{ if(NR==4) { print diff}
                              else {print $0} } ' filename > newfilename

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to change a specific character in a file

Hi, I have a data file with following structure: a|b|c|d|3|f1|f2|f3 a|b|c|d|5|f1|f2|f3|f4|f5 I want to change this data to: a|b|c|d|3|f1;f2;f3 a|b|c|d|5|f1;f2;f3;f4;f5 Data in column 5 tells the number of following fields. All fields delimiter after the 5th column needs to be... (6 Replies)
Discussion started by: sdubey
6 Replies

2. UNIX for Dummies Questions & Answers

Script to change/find/delete/install a specific file

Hi Very much a newbie to UNIX & scripting, but have identified an area within work that would benefit from being automated, as its repeated manually very often, and it looks like the ideal first script! What I need to do is change directory to a users home (cd ~), and then find and remove a... (6 Replies)
Discussion started by: Great Uncle Kip
6 Replies

3. Shell Programming and Scripting

Change specific ip address in a file

I need to change a line from a xen cfg file using sed if it's possible. The original line is: vif = I want to change ONLY the IP address of the second part ==> ip=10.1.10.4 to another IP --> ip=192.222.11.6 The first one ip=123.456.789.123 keeps untouchable. My new line shoud... (9 Replies)
Discussion started by: iga3725
9 Replies

4. Shell Programming and Scripting

How to change a number on a specific lines in a file with shell?

Hello My problem is that I want to change some specific numbers in a file. It is like, 2009 10 3 2349 21.3 L 40.719 27.388 10.8 FRO 7 0.8 1.1LFRO 2.6CFRO 1.1LMAM1 GAP=157 1.69 5.7 5.9 5.8 0.5405E+01 0.4455E+00 0.1653E+02E STAT SP IPHASW D HRMM SECON CODA AMPLIT... (11 Replies)
Discussion started by: miriammiriam
11 Replies

5. Shell Programming and Scripting

How to change a number on a specific line with cshell or shell?

Hello all, I need to change a number in a file by adding some residuals respectively To make it clear, I need to add 0.11 to the number between 24-28 (which is below the SECON) for all the lines starting with FRR1 or I need to add 0.13 to the number between 24-28 (which is below the... (9 Replies)
Discussion started by: miriammiriam
9 Replies

6. UNIX for Dummies Questions & Answers

How can I search and change an specific string in a file

Dear All, New to Linux/Unix OS, my Linux version is 2010 x86_64 x86_64 x86_64 GNU/Linux As titled, I wonder if you can help to provide a solution to find and change an specific string in a file The file include a lots of data in following configuration but might be various in... (3 Replies)
Discussion started by: axel
3 Replies

7. Shell Programming and Scripting

how to change specific value for a entry in the file

Hello All, can someone please suggest me a one line command to change a specific value that is associated to an entry in the file. for example #more schedulefile quartz.job.manual.bonus.schedule=0 0 9 ? * * # it should be changed to #more schedulefile... (5 Replies)
Discussion started by: bobby320
5 Replies

8. Shell Programming and Scripting

To change Specific Lines in An XML file

hi Guys, this is my requirement, there is a huge xml file of this i have to change 3 lines with out opening the file /users/oracle > cat lnxdb-pts-454.xml|egrep "s_virtual|s_cluster|s_dlsnstatus" <cluster_port oa_var="s_clusterServicePort">9998</cluster_port> <host... (2 Replies)
Discussion started by: smarlaku
2 Replies

9. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

10. Shell Programming and Scripting

awk to change specific string to new value if found in text file

I am trying to use awk to change a specific string in a field, if it is found, to another value. In the tab-delimited file the text in bold in $3 contains the string 23, which is always right before a ., if it is present. I am trying to change that string to X, keeping the formatting and the... (3 Replies)
Discussion started by: cmccabe
3 Replies
Patch(3pm)						User Contributed Perl Documentation						Patch(3pm)

NAME
Text::Patch - Patches text with given patch SYNOPSIS
use Text::Patch; $output = patch( $source, $diff, STYLE => "Unified" ); use Text::Diff; $src = ... $dst = ... $diff = diff( $src, $dst, { STYLE => 'Unified' } ); $out = patch( $src, $diff, { STYLE => 'Unified' } ); print "Patch successful" if $out eq $dst; DESCRIPTION
Text::Patch combines source text with given diff (difference) data. Diff data is produced by Text::Diff module or by the standard diff utility (man diff, see -u option). patch( $source, $diff, options... ) First argument is source (original) text. Second is the diff data. Third argument can be either hash reference with options or all the rest arguments will be considered patch options: $output = patch( $source, $diff, STYLE => "Unified", ... ); $output = patch( $source, $diff, { STYLE => "Unified", ... } ); Options are: STYLE => 'Unified' STYLE can be "Unified", "Context" or "OldStyle". The 'Unified' diff format looks like this: @@ -1,7 +1,6 @@ -The Way that can be told of is not the eternal Way; -The name that can be named is not the eternal name. The Nameless is the origin of Heaven and Earth; -The Named is the mother of all things. +The named is the mother of all things. + Therefore let there always be non-being, so we may see their subtlety, And let there always be being, @@ -9,3 +8,6 @@ The two are the same, But after they are produced, they have different names. +They both may be called deep and profound. +Deeper and more profound, +The door of all subtleties! TODO
Interfaces with files, arrays, etc. AUTHOR
Vladi Belperchinov-Shabanski "Cade" <cade@biscom.net> <cade@datamax.bg> <cade@cpan.org> http://cade.datamax.bg VERSION
$Id: Patch.pm,v 1.6 2007/04/07 19:57:41 cade Exp $ perl v5.10.1 2010-10-04 Patch(3pm)
All times are GMT -4. The time now is 09:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy