Sponsored Content
Top Forums Shell Programming and Scripting sed doubt - search and substitute string from variable. Post 302455994 by Franklin52 on Thursday 23rd of September 2010 02:23:43 AM
Old 09-23-2010
Or:
Code:
b=_EDITED

while read i
do
  sed "s!$i!$i$b!" input.txt > temp
  mv temp input.txt
done < read.txt

If your sed version supports the -i option:
Code:
b=_EDITED

while read i
do
  sed -i "s!$i!$i$b!" input.txt
done < read.txt

This User Gave Thanks to Franklin52 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

2. Shell Programming and Scripting

search a string in a line and save it in a variable

Hi I want to read a file line by line and search for a particular string in each line(say for example string containing @ )and save that string into a variable. Can someone suggest me the way to implement it.I am using K- shell Thanks Ishita (5 Replies)
Discussion started by: Ishita
5 Replies

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

4. Shell Programming and Scripting

Trying to use a variable pulled from a for statement in a search string

Guys I am having trouble trying to pull some data from a file using a value returned from a for statement. Any help would greatly be apprecaited. I can't seem to get my script to pass the variable. I am trying to pull the 2 lines below the line that has the "pool name" so that i can get the... (5 Replies)
Discussion started by: scottzx7rr
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

How to substitute variable in sed for special character?

Hi , I have input file like below Hi this is "vinoth". Hi happy to work with 'unix' USA(united states of America) My script variables are below : Dquote=Ộ Squote=&#$567 Obrac=&^986 Cbrac=&^745 I want to read the variables in my SED command to replace the double quote,single... (9 Replies)
Discussion started by: vinothsekark
9 Replies

7. Shell Programming and Scripting

String search between patterns using sed

Hi, I am trying to find a way to get sed/awk/grep to help me find a string in a log file that exists between two datestamps and then print the preceding datestamp up to the next datestamp. Here is an example of my logfile: +++ 2013/03/28 17:01:37.085 SIGNALING HIGH ACTIVE Failure Response... (5 Replies)
Discussion started by: raytx
5 Replies

8. Shell Programming and Scripting

Search for 2 string in 2 lines with sed ?

Hi ! I want to search a string in all lines with sed. If that string is there, i want to look for an other string in the next line.If that string is there i want to put an other line under it. eg: aaa bbb ccc ddd cat bla.txt | sed -e '/aaa/a\' -e ' \!!!' in the upper case, i would... (6 Replies)
Discussion started by: fugitivus
6 Replies

9. Shell Programming and Scripting

[sed]: Substitute a string with a multiline value

Dear all, I try to replace a string of characters in a file (MyFile.txt) by a multiline value of the variable "Myvar": $ cat MyFile.txt DESCRIPTION '@TargetTable SCHEMA' ( @InputFlowDef ); $ The content of Myvar: $ echo "$Myvar" col1 , col2 , col3 $ (4 Replies)
Discussion started by: dae
4 Replies

10. Shell Programming and Scripting

Search for string in column using variable: awk

I'm interested to match column pattern through awk using an external variable for data: -9 1:751343:T:A -9 0 T A 0.726 -5.408837e-03 9.576603e-03 7.967536e-01 5.722312e-01 -9 1:751756:T:C -9 0 T C 0.727 -5.360458e-03 9.579447e-03 7.966977e-01 5.757858e-01... (7 Replies)
Discussion started by: genome
7 Replies
DPHYS-SWAPFILE(8)					      System Manager's Manual						 DPHYS-SWAPFILE(8)

NAME
dphys-swapfile - set up, mount/unmount, and delete an swap file SYNOPSIS
dphys-swapfile setup|swapon|swapoff|uninstall DESCRIPTION
dphys-swapfile computes the size for an optimal swap file (and resizes an existing swap file if necessary), mounts an swap file, unmounts it, and and delete it if not wanted any more. OPTIONS
There is only one parameter, an command, which can be either of these: setup Tells dphys-swapfile to compute the optimal swap file size and (re-)generate an fitting swap file. Default it 2 times RAM size. This can be called at boot time, so the file allways stays the right size for current RAM, or run by hand whenever RAM size has changed. swapon and swapoff These run the swapon and swapoff commands on the swapfile. Note that direct swapon/off from /etc/fstab is not possible, as that is (at least on Debian) done in the same script that mounts /var (which is where the swap file most likely resides). And we need to do our setup between those actions. So pass up /etc/fstab, and do our own swapon/off. uninstall Gets rid of an unwanted swap file, reclaiming the disk space. CONFIG
The config file /etc/dphys-swapfile allows the user to set up the working environment for dphys-swapfile. This config file is a sh script fragment full of assignments, which is sourced. Standard sh syntax rules apply. Assignments are: CONF_SWAPFILE Set where the swap file should be placed. Defaults to /var/swap. It is unlikely that you will need to change this, unless you have very strange partitioning, and then you will most likely be using an swap partition anyway. CONF_SWAPSIZE Force file size to this. Default is 2*RAM size. This is unlikely to be needed, unless in strange diskspace situations. Note that swap enabled and smaller than RAM causes kernal-internal VM trouble on random systems. CONF_SWAPFACTOR Set the relation between RAM and swap size. Must be an integer. Defaults to 2 which means swap size = 2 * RAM size CONF_MAXSWAP Set maximum size of the swap file in MBytes. Defaults to 2048 which was the former kernel limit for the swapfile size and is now a limit to prevent unusual big swap files on systems with a lot of RAM. FILES
/etc/dphys-swapfile user config $CONF_SWAPFILE the swap file, target of the whole action (defaults to /var/swap) EXAMPLES
dphys-swapfile is usually run at system startup and shutdown from an /etc/init.d (or /etc/rc.d) script, such as this (minimal) one: #!/bin/sh # /etc/init.d/dphys-swapfile - automatically set up an swapfile # author franklin, last modification 2004.06.04 # This script is copyright ETH Zuerich Physics Departement, # use under either modified/non-advertising BSD or GPL license case "$1" in start) /sbin/dphys-swapfile setup /sbin/dphys-swapfile swapon ;; stop) /sbin/dphys-swapfile swapoff ;; esac exit 0 If an sysadmin wants to have his swapfile in annother place, say /var/run/swap, he can use: In /etc/dphys-swapfile: CONF_SWAPFILE=/var/run/swap AUTHOR
franklin@phys.ethz.ch, http://www.phys.ethz.ch/~franklin/ D-PHYS Swapfile Tools 2006.09.15 DPHYS-SWAPFILE(8)
All times are GMT -4. The time now is 06:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy