SED based on file lookup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED based on file lookup
# 1  
Old 06-11-2009
SED based on file lookup

Newb here trying to figure this one out. Smilie

I am trying to create a SED (or some other idea) line that will replace the data field if the original text is seen in a separate text file. The lookup file would be line delimted.

For example: sed 's/<if in file>/YES/'

File structure:
1-1
3-14
5-20
etc...

Is this possible??
# 2  
Old 06-11-2009
Hello!

Per forum rules, and the benefit of all users, please search the forums before posting a question.

You can easily search the forums using our internal Google search engine or our advanced internal search engine. You can also search our huge UNIX and Linux database by user generated tags or search the database for unanswered questions and provide an answer.

Thank you.

The UNIX and Linux Forums
# 3  
Old 06-11-2009
Perhaps a hint in the right direction then?

I've done quite a bit of searching of this site and I don't think my search query is correct.

I've been trying different combination's of "while read" and "do" but still don't understand how it all fits together with a reference file or even if that is the right direction.
# 4  
Old 06-11-2009
lookup.txt
Code:
1-39
3-14
5-20

file2modify.txt
Code:
asdfkasdf asldkfj 1 sdfkj 3
oiweu asdfkh 8 sadkf 5 asdfkj 3 11

Code:
nawk 'FNR==NR {a[$1]=$2;next} {for(i=1;i<=NF;i++) if ($i in a) $i=a[$i]}1' FS='-' lookup.txt FS=' ' file2modify.txt

Produces:
Code:
asdfkasdf asldkfj 39 sdfkj 14
oiweu asdfkh 8 sadkf 20 asdfkj 14 11

YMMV
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete the records in file based on lookup file.

Hi I have two files one.txt and two.txt one.txt 123 324 456 235 456 two txt abc one 000 123 abc abc one 000 456 abc abc one 000 122 abc abc one 000 111 abc My question here is, the records which are present in one.txt has to deleted in second file two.txt my output result... (2 Replies)
Discussion started by: Ganesh L
2 Replies

2. Shell Programming and Scripting

Help required on Length based lookup

Hi, I have two files one (abc.txt) is having approx 28k records and another (bcd.txt) on is having 112k records, the length of each files are varried. I am trying to look up abc.txt file with bcd.txt based on length, where ever abc.txt records are matching with bcd.txt I am successful match... (8 Replies)
Discussion started by: rramkrishnas
8 Replies

3. Shell Programming and Scripting

Filtering duplicates based on lookup table and rules

please help solving the following. I have access to redhat linux cluster having 32gigs of ram. I have duplicate ids for variable names, in the file 1,2 are duplicates;3,4 and 5 are duplicates;6 and 7 are duplicates. My objective is to use only the first occurrence of these duplicates. Lookup... (4 Replies)
Discussion started by: ritakadm
4 Replies

4. Shell Programming and Scripting

Combined sed+awk for lookup csv file

have written a combined sed+awk to perform a lookup operation which works but looking to enhance it. looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so: cat foo make,model,engine,trim,value... (6 Replies)
Discussion started by: jack.bauer
6 Replies

5. Shell Programming and Scripting

Lookup on large file based on a temp file

hello guys Please help me with the below issue I have two files one base file another lookupfile base file abc-001 bcd-001 cde-001 Lookupfile abc-001|11|12 abc-001|11|12 abc-001|11|12 (6 Replies)
Discussion started by: Pratik4891
6 Replies

6. Shell Programming and Scripting

Sed variable from lookup table

I have a file with the following format --TABLEA_START-- field1=data1;field2=data2;field3=data3 --TABLEA_END-- --TABLEB_START-- field1=data1;field2=data2;field3=data3 --TABLEB_END-- --TABLEA_START-- field1=data1;field2=data2;field3=data3 ... (0 Replies)
Discussion started by: milo7
0 Replies

7. Shell Programming and Scripting

using sed to conditionally extract stanzas of a file based on a search string

Dear All, I have a file with the syntax below (composed of several <log ..... </log> stanzas) I need to search this file for a number e.g. 2348022225919, and if it is found in a stanza, copy the whole stanza/section (<log .... </log>) to another output file. The numbers to search for are... (0 Replies)
Discussion started by: aitayemi
0 Replies

8. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

9. Shell Programming and Scripting

Split a file based on pattern in awk, grep, sed or perl

Hi All, Can someone please help me write a script for the following requirement in awk, grep, sed or perl. Buuuu xxx bbb Kmmmm rrr ssss uuuu Kwwww zzzz ccc Roooowwww eeee Bxxxx jjjj dddd Kuuuu eeeee nnnn Rpppp cccc vvvv cccc Rhhhhhhyyyy tttt Lhhhh rrrrrssssss Bffff mmmm iiiii Ktttt... (5 Replies)
Discussion started by: kumarn
5 Replies

10. Shell Programming and Scripting

sed & awk--get section of file based 2 params

I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)
Discussion started by: Andy Cook
12 Replies
Login or Register to Ask a Question