Sponsored Content
Top Forums Shell Programming and Scripting How to replace a string in a file using another file as source? Post 303002637 by Akshay Hegde on Tuesday 29th of August 2017 02:46:33 PM
Old 08-29-2017
Code:
awk 'FNR==NR{ a[$1] = $2; next} { for(i in a)gsub(i, a[i]) }1'  string_list_file file > outfile

Here is example to start

Code:
akshay@db-3325:/tmp$ cat string_list_file 
foo bar
jack john
me you

akshay@db-3325:/tmp$ cat file 
1 2 3 jack 5
me 2 3 foo 5
me jack foo 4 5

akshay@db-3325:/tmp$ awk 'FNR==NR{ a[$1] = $2; next} { for(i in a)gsub(i, a[i]) }1'  string_list_file file 
1 2 3 john 5
you 2 3 bar 5
you john bar 4 5

This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

2. Shell Programming and Scripting

How To Replace A String In File With A String Containing Windows File Path

Hi, I have a file with the following contents # Lines that start with a # are comments. # # Calling TOAD like this will perform a comparison from command line : # # "C:\Program Files\Quest Software\Toad for Oracle 9.6\toad.exe" -c... (2 Replies)
Discussion started by: rajan_san
2 Replies

3. Shell Programming and Scripting

find and replace a string in a file without the use of temp file

Hi - I am looking for a replacing a string in a in multiple *.sql files in directory with a new string without using a temporary file Normally I can use sed command as below for W in ls `FILE*.sql` do sed 's/OLD/NEW/g' $W > TEMPFILE.dat mv TEMPFILE.dat $W done But Here in my... (9 Replies)
Discussion started by: raghutapal
9 Replies

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

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

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

7. Shell Programming and Scripting

Replace string in a file with some content indexed from another file.

We have two files file 1: (usually small, ~100 lines), each line contains a : separated index, value e.g 2: Apple 1: Banana 5: Pear 7: Orange File 2: (usually large, 10 million lines or more), each line contains a single string value. e.g xyz1 xyz2 xyz3 xyz4 xyz5 xyz6 xyz7 Now... (2 Replies)
Discussion started by: AlokKumbhare
2 Replies

8. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

9. UNIX for Dummies Questions & Answers

Replace character string in txt file using input file(S)

Hi I have a large txt file on my AIX server and I need to replace some text using two other files. So filename1 has about 500 lines similar to: txtcode SYStem100 I have the string I want to change in string2 and the new stringname in string3. Does anyone know a way of doing this? I have... (1 Reply)
Discussion started by: Grueben
1 Replies

10. Shell Programming and Scripting

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: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
JACK-STDOUT(1)						      General Commands Manual						    JACK-STDOUT(1)

NAME
jack-stdout - write JACK audio data to stdout SYNOPSIS
jack-stdout [OPTIONS] port1 [ port2 ...] DESCRIPTION
jack-stdout captures audio from JACK and writes raw data to standard-output. The number of given ports detemine the number of audio channels that are used. If more than one channel is given, the audio-sample data will be interleaved. OPTIONS
-b, --bitdepth BITS Specify the bit-depth of each sample. For integer-encoding this can be 16 or 24. The default is 16. This setting is only used for integer encoding: Floating-point samples will always be 32 bit wide. -d, --duration SEC Specify the time for which jack-stdout should run in seconds. A value less than 1 means to run indefinitely. The default is 0. -e, --encoding FORMAT Set the output format of the data: signed-integer, unsigned-integer, floating-point (default: signed) -h, --help Print a brief usage information -L, --little-endian Write little-endian data or native-byte-order float (this is the default) -B, --big-endian Output big-endian data or swap the byte-order of floating-point -q, --quiet Inhibit usual output. This affects information and buffer-overflow warnings but not setup-errors. -S, --bufsize SAMPLES Choose the internal buffer-size in samples. The default size is 65536. The given value will be multiplied by the number of channels and bit-depth to get the size of the ring-buffer. EXAMPLES
jack-stdout xmms_0:out_1 xmms_0:out_2 | mono ~/Desktop/Downloads/JustePort.exe - 10.0.1.6 0 jack-stdout -b 24 -e unsigned -B system:capture_1 system:capture_2 | sox -t raw -r 48k -e unsigned -b 24 -B -c 2 - /tmp/recording.wav jack-stdout system:capture_1 system:capture_2 | oggenc -r -R 48000 -B 16 -C 2 - > /tmp/recording.ogg jack-stdout system:capture_1 | oggenc -r -R 48000 -B 16 -C 1 - | oggfwd -p -n "my live stream" localhost 5900 hackme live.ogg AUTHOR
Robin Gareus <robin@gareus.org>. SEE ALSO
http://jackaudio.org/, 29 March 2011 JACK-STDOUT(1)
All times are GMT -4. The time now is 01:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy