change record detail...in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change record detail...in file
# 1  
Old 03-11-2007
change record detail...in file

hello,

I have a file with the following record:
a.txt

AAjohn10123403
AAmary10298411
AAcat120192a1030
AApeter094857
AAmaybb019485

I have a list called b.txt, if matched the name and it will change to new name (which is after space)
john1 cancel
cat12 cat12
peter peter
mary1 cancel
maybb maybb

can help?
# 2  
Old 03-11-2007
Try...
Code:
awk 'NR==FNR{a[$1]=$2;next}{for(x in a)sub(x,a[x])};1' b.txt a.txt

# 3  
Old 03-11-2007
Quote:
Originally Posted by Ygor
Try...
Code:
awk 'NR==FNR{a[$1]=$2;next}{for(x in a)sub(x,a[x])};1' b.txt a.txt

thx! I will try it later...but can you explain to me above statement? so that I can learn some...
# 4  
Old 03-12-2007
Quote:
Originally Posted by Ygor
Try...
Code:
awk 'NR==FNR{a[$1]=$2;next}{for(x in a)sub(x,a[x])};1' b.txt a.txt

not work..


awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1
# 5  
Old 03-12-2007
If on Solaris, use nawk.
# 6  
Old 03-12-2007
Quote:
Originally Posted by Ygor
If on Solaris, use nawk.
Great...it's work!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

2. Shell Programming and Scripting

Detail on For loop for multiple file input and bash variable usage

Dear mentors, I just need little explanation regarding for loop to give input to awk script for file in `ls *.txt |sort -t"_" -k2n,2`; do awk script $file done which sorts file in order, and will input one after another file in order to awk script suppose if I have to input 2 or... (4 Replies)
Discussion started by: Akshay Hegde
4 Replies

3. Shell Programming and Scripting

awk change one value in csv based on another value in the record

I've found 2 great discussions on this forum that are tied to my question, but for some reason, neither solution works for me. I have a CSV file with many records, up to 150+ at some times. Many records have a value of H in $1. For those records, I need to add today's current date in $20. I'm... (4 Replies)
Discussion started by: mrvitas
4 Replies

4. UNIX for Dummies Questions & Answers

change order of fields in header record

Hello, after 9 months of archiving 1000 files, now, i need to change the order of fields in the header record. some very large, space padded files. HEADERCAS05212008D0210DOMEST01(spacepadded to record length 210) must now be 05212008HEADERCASD0210DOMEST01(spacepadded to record length 210) ... (1 Reply)
Discussion started by: JohnMario
1 Replies

5. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

6. Shell Programming and Scripting

Pivot variable record length file and change delimiter

Hi experts. I got a file (500mb max) and need to pivot it (loading into ORCL) and change BLANK delimiter to PIPE |. Sometimes there are multipel BLANKS (as a particular value may be BLANK, or simply two BLANKS instead of one BLANK). thanks for your input! Cheers, Layout... (3 Replies)
Discussion started by: thomasr
3 Replies

7. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies

8. Shell Programming and Scripting

change some record item

Hi all, I have a file with over 10,000 line, but I would like to update/add some code number (such as 062 below) into the line with <phone number> below: 11111<name> john matin <name> 12345<phone number> 123456 <phone number> 34556 <address> 1234 lucky road <address> 11111<name> john... (7 Replies)
Discussion started by: happyv
7 Replies

9. Solaris

how to use the grep to find detail in a file

I need to search say a customer account number in a selection of files using 'grep', for example, I need to do the following; using grep to locate '020 117 in the mail files (mail files-txt) cheers (1 Reply)
Discussion started by: etravels
1 Replies

10. UNIX for Dummies Questions & Answers

Getting detail out of a log file...

I'd like to peruse a log file and from it generate another file from the first instance of "Jul 11" to the first instance of "Jul 18" within the log file. (3 Replies)
Discussion started by: Cameron
3 Replies
Login or Register to Ask a Question