Sponsored Content
Top Forums Shell Programming and Scripting Replace string of a file with a string of another file for matches using grep,sed,awk Post 303026449 by Paras Pandey on Wednesday 28th of November 2018 04:51:07 AM
Old 11-28-2018
Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: -->

Code:
cat comp.pkglist 
Package list:  nss-util-devel-3.28.4-1.el6_9.x86_64 
Version Change: 3.28.4 --> 3.36.0 
Release Change: 1.el6_9 --> 1.el6 

Package list:   tzdata-2018e-3.el6.noarch 
Version Change: 2018e --> 2018g 
Release Change: 3.el6 --> 1.el6

for every package name I need to search in /tmp directory and replace it`s version from old version to new version and old release to new release:

Code:
grep -ri -n tzdata /tmp/. 
/tmp/core.pkglist:578:package tzdata                  2018e 3.el6    arch noarch  

sed -i '578s/2018e/2018g/' /tmp/core.pkglist // To replace '2018e by 2018g in 578th line.

How can I make it work for all packages in the comp.pkglist file to replace it`s old version to new version and old release to new release in any file under the directory /tmp.

The script should :
1) Run a loop with inputs as the name of the package in the comp.pkglist.
2) It should then grep for that package name in the /tmp directory to know which file contains the package.
Code:
grep -ri -n tzdata /tmp/. /tmp/core.pkglist:578:package tzdata                  2018e 3.el6    arch noarch

3) Then it should replace old version/old release of the same package with new version.
Code:
 sed -i '578s/2018e/2018g/' /tmp/core.pkglist


Last edited by RudiC; 11-28-2018 at 07:38 AM.. Reason: Changed ICODE to CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed, grep, awk, regex -- extracting a matched substring from a file/string

Ok, I'm stumped and can't seem to find relevant info. (I'm not even sure, I might have asked something similar before.): I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies

2. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

3. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

4. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

sed or awk to replace a value in a certain line from another file containing a string

Hi experts, In my text file I have the following alot of lines like below. input.k is as follows. 2684717 -194.7050476 64.2345581 150.6500092 0 0 2684718 -213.1575623 62.7032242 150.6500092 0 0 *INCLUDE $# filename... (3 Replies)
Discussion started by: hamnsan
3 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. Shell Programming and Scripting

Replace all string matches in file with unique random number

Hello Take this file... Test01 Ref test Version 01 Test02 Ref test Version 02 Test66 Ref test Version 66 Test99 Ref test Version 99 I want to substitute every occurrence of Test{2} with a unique random number, so for example, if I was using sed, substitution would be something... (1 Reply)
Discussion started by: funkman
1 Replies
d-shlibmove(1)							  d-shlibs manual						    d-shlibmove(1)

NAME
d-shlibmove - Move shared library files around in Debian package creation process SYNOPSIS
d-shlibmove [options] shared-library.so DESCRIPTION
Call this program in debian/rules as a replacement of dh_movefiles for shared library packages. It also checks debian/control for validity. OPTIONS
--movedev [filename] [relative dir-path] Install file into relative directory path within the -dev package. The dir will be created with install -d and the file will be moved. --moveshl [filename] [relative dir-path] Install file into relative directory path within the shared library runtime package. The dir will be created with install -d and the file will be moved. --movedevdoc [filename] Install file into the documentation directory of -dev package. The dir will be created with install -d and the file will be moved. Added in version 0.4 --extralib [shared-library.so] Install the shared library in the same package as the main shared library. --multiarch By default d-shlibmove installs the shared library and any extralibs into /usr/lib. Add this flag to install them into /usr/lib/<architecture-tripplet> instead. Added in version 0.48 --commit By default d-shlibmove runs in a dry-run mode. Add this flag to make the moving actually happen. --suffix [suffix to add to shared library package] Add a suffix to shared library package. This is a workaround when binary interface to package changed, and some fixup to Debian packaging needs to be done. Added in version 0.3 --devsuffix [suffix to add to development package] Add a suffix to development package. For making incompatible development package. --shlibs-local [current-version] Create a debian/shlibs.local file to use, and specify current-version of shared library package. You need to remove debian/shlibs.local, because this only appends to, not overwrite. Added in version 0.3 --devunversioned Install into unversioned development package. Added in version 0.42 --ignorelibdep Suppress shlib dependency. Useful when dynamically resolved e.g. using CDBS. Added in version 0.42 --c102 Add c102 suffix to package names, for C++ ABI transition. Added in version 0.8 --ldbl Add dbl suffix to package names. Added in version 0.35 --include-a Install the *.a files. This is the default behavior. Added in version 0.51 --exclude-a Avoid installing *.a files. Added in version 0.51 --include-la Install the *.la files. This is the default behavior. Added in version 0.45 --exclude-la Avoid installing *.la files. Added in version 0.45 --override [override statement] Add an overriding sed expression, which looks like --override s/libshared1-dev/libshared-dev/. This expression is executed after the other rules. Multiple --override can be specified. Added in version 0.30 EXIT CODE
Return 1 on error. Return 2 on dry-run. Return 0 on success. EXAMPLES
The following is a sample command-line of a hypothetical package installation. d-shlibmove --commit --movedev "debian/tmp/usr/include/*" usr/include --extralib debian/tmp/usr/lib/libhomeman-pthread.so debian/tmp/usr/lib/libhomeman.so AUTHOR
Junichi Uekawa <dancer@debian.org> <dancer@netfort.gr.jp> SEE ALSO
d-devlibdeps (1) Debian GNU/Linux 2002 May 3 d-shlibmove(1)
All times are GMT -4. The time now is 01:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy