Sponsored Content
Top Forums Shell Programming and Scripting Replacing values in a file based on values in another file Post 302433935 by pparthiv on Thursday 1st of July 2010 02:27:21 AM
Old 07-01-2010
Replacing values in a file based on values in another file

Hi

I have 2 files:-

1. List of files which consists of names of some output files.
2. A delimited file; delimted by "|"

I want to replace the value of the $23 (23rd column) in the delimited file with name in the first file. It is always position to position. Meaning first row of the first file to replace the $23 in the first row of second file and so on. Both the files will have equal number of lines.

e.g.

Code:
File 1:
=======
AAABBBCC_HHGGTT_34_20100701113142_001_D_00_0.pdf
11122233_HHGGTT_34_20100701113142_001_D_00_0.pdf
55566677_HHGGTT_34_20100701113142_001_D_00_0.pdf
88899900_HHGGTT_34_20100701113142_001_D_00_0.pdf

File 2:
=======
1|10|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00001|2010_01_4010093_001_00_aa.pdf|
1|11|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00002|2010_01_4010162_001_00_aa.pdf|
1|17|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00003|2010_01_4010163_001_00_aa.pdf|
1|22|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00004|2010_01_4010164_001_00_aa.pdf|


Desired Output:
================

1|10|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00001|AAABBBCC_HHGGTT_34_20100701113142_001_D_00_0.pdf|
1|11|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00002|11122233_HHGGTT_34_20100701113142_001_D_00_0.pdf|
1|17|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00003|55566677_HHGGTT_34_20100701113142_001_D_00_0.pdf|
1|22|HHHH|9|112222||0040400||445566|S|O|X||||20100701113142-31.12.2009|667553AT|GST||||00004|88899900_HHGGTT_34_20100701113142_001_D_00_0.pdf|

Can somebody please help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract from a file based on values in another file

Hello, I have two files that have delimited entries as shown below. I would like to use either Perl or Shell script to extract all the rows in File 1 corresponding to values in File 2 and output it to another File. File 1 ------- 1 36 24 Object1 2 45 36 Object2 3 96 ... (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

2. Shell Programming and Scripting

Replacing File values

Currently I am using the tr command in 3 scenarios for a ksh script. 1) Replacing any spaces in the file with a ~ tr ' ' '~' <$orignalFile> $newFile 2) After certain processing is done at the end of the scirpt i convert the Tilde back to spaces tr ' ' '~' <$newFile> $newFile2 3) Last... (4 Replies)
Discussion started by: hgjdv
4 Replies

3. Shell Programming and Scripting

File manipulation based on values in file

Hi, using Shell to do some file manipulation here. Input - input.txt "2006/2007", "string1a","string2v","stringf3" "2006/2007", "string12b","string30c","string10d" "2006/2007", "string22","string22","string11" "2007/2008", "string1a","string2v","stringf3" "2007/2008",... (5 Replies)
Discussion started by: pgop
5 Replies

4. UNIX for Dummies Questions & Answers

Find and Replace based on values in an file

I have a file in which I want to do multiple find and replace of strings. For a single replace I can implement: sed -i 's/old/new/' <input_file> I have a second file that contains the old and the new values like the arbitrary example below: old new xyz pqr ab 756 rst pqr... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

5. UNIX for Dummies Questions & Answers

count values based on contents of another file

Hello, I have two files as shown below: test1 678 679 689 690 710 test2 1 678 654 800 676 791 689 900 I want to get a count of lines from test2 whose columns bound the values in test1 I tried running the code below; however am getting wrong results. (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

6. Shell Programming and Scripting

Replacing column 1 in one file with values in other file

Please help me with an shell / awk script to achieve following; File-1: ABCDW01 12322 23322 BDADW01 22232 24453 EDFAW00 32232 23422 and so on, notice that the first coloumn is a code and the another file contains the real value of each entry in the first colum above but not in a... (4 Replies)
Discussion started by: digipak
4 Replies

7. Shell Programming and Scripting

Replacing string values from a File

I want to replace string values from a file to a file For eg : File1 has 30 lines of string with values, those specific values needs to be changed in file2 and remaining values in file2 should be as it is. For example: From file (File1) cluster.name=secondaryCluster To replace File... (9 Replies)
Discussion started by: sriram003
9 Replies

8. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

9. Shell Programming and Scripting

awk to look up values in File 2 from File 1, & printingNth field of File1 based value of File2 $2

I have two files which are the output of a multiple choice vocab test (60 separate questions) from 104 people (there are some missing responses) and the question list. I have the item list in one file (File1) Item,Stimulus,Choice1,Choice2,Choice3,Choice4,Correct... (5 Replies)
Discussion started by: samonl
5 Replies

10. UNIX for Beginners Questions & Answers

Replacing values inside a file.

Good day guys, I'm having trouble in creating a logic when it comes to replacing the values inside a file. I tried using sed command but it just doesn't work the way I want it to be. Here is what I'm trying to achieve. If my input file contains the values below. NAME++GUEST1 ++GUESS2++... (3 Replies)
Discussion started by: asdfghjkl
3 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 02:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy