awk or sed one liner


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk or sed one liner
# 1  
Old 10-15-2012
awk or sed one liner

I have a data base of part numbers:
Code:
AAA Thing1
BBB Thing2
CCC Thing3

File one is a list of part numbers:
Code:
XXXX AAA234
XXXX BBB678
XXXX CCC2345

Is there a sed one-line that would compare a data base with and replace the part numbers so that the output looks like this?

Code:
XXXX AAA234 Thing1
XXXX BBB678 Thing2
XXXX CCC2345 Thing3

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 10-15-2012 at 05:20 PM.. Reason: code tags, please!
# 2  
Old 10-15-2012
What type of database are you using(i.e. oracle, db2, etc.)?
How are you retrieving the row from the database table and what columns does each row have?
# 3  
Old 10-15-2012
the database is just a text file
# 4  
Old 10-15-2012
Code:
awk 'FNR==NR{db[$1]=$2;next} {print $0, db[substr($2,1,3)]}' dbFile listFile

# 5  
Old 10-15-2012
its echoing back everything
# 6  
Old 10-15-2012
Quote:
Originally Posted by jimmyf
its echoing back everything
what does that mean?
given your sample files, it gets the desired output that you quoted.

What's the issue?
This User Gave Thanks to vgersh99 For This Post:
# 7  
Old 10-15-2012
ok I had to use nawk! thank you very much!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed one-liner

I have a data base of part numbers: AAA Thing1 BBB Thing2 CCC Thing3 File one is a list of part numbers: AAA234 BBB678 CCC2345 Is there a sed one-line that would compare a data base with and replace the part numbers so that the output looks like this? AAA234 Thing1 BBB678 Thing2... (5 Replies)
Discussion started by: jimmyf
5 Replies

2. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

3. UNIX for Dummies Questions & Answers

One liner pattern search with awk/sed/grep

I have an array containing bunch of characters. I have to check this array for specific character and if "Not Found than" use a goto statement to go to USAGE set options = (A B C D E F) @ i = 0 while ($i <= ${#options}) if ($options != "F" || $options != "D") then goto USAGE endif @... (1 Reply)
Discussion started by: dixits
1 Replies

4. UNIX for Dummies Questions & Answers

renaming multiple files using sed or awk one liner

hi, I have a directory "test" under which there are 3 files a.txt,b.txt and c.txt. I need to rename those files to a.pl,b.pl and c.pl respectively. is it possible to achieve this in a sed or awk one liner? i have searched but many of them are scripts. I need to do this in a one liner. I... (2 Replies)
Discussion started by: pandeesh
2 Replies

5. Shell Programming and Scripting

help with sed one liner

hey everyone, I want to remove some characters from a string that i have with sed. For example if my string is: a0=bus a1=car a2=truck I want my output to look like this: bus car truck So i want to delete the two characters before the = and including the =. This is what i came up with... (3 Replies)
Discussion started by: GmGeubt
3 Replies

6. Shell Programming and Scripting

Need an awk / sed / or perl one-liner to remove last 4 characters with non-unique pattern.

Hi, I'm writing a ksh script and trying to use an awk / sed / or perl one-liner to remove the last 4 characters of a line in a file if it begins with a period. Here is the contents of the file... the column in which I want to remove the last 4 characters is the last column. ($6 in awk). I've... (10 Replies)
Discussion started by: right_coaster
10 Replies

7. Shell Programming and Scripting

SED | Awk flat file one liner

sed awk one liner (2 Replies)
Discussion started by: jap2614
2 Replies

8. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

9. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

10. UNIX for Dummies Questions & Answers

Awk/Sed One liner for text replacement

Hi group, I want to replace the occurance of a particular text in a paragraph.I tried with Sed,but Sed only displays the result on the screen.How can i update the changes in the original file??? The solution should be a one liner using awk and sed. Thanks in advance. (5 Replies)
Discussion started by: bishnu.bhatta
5 Replies
Login or Register to Ask a Question