Visit Our UNIX and Linux User Community


using nawk to concate the fields


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers using nawk to concate the fields
# 1  
Old 01-25-2008
Power using nawk to concate the fields

I have the the following question:

# cat report.lis | nawk -F: '{ if($0 ~ "^BE NO:") print "report_"$2".lis"}' Smilie
.lisrt_ 111
.lisrt_ 111
.lisrt_ 222
.lisrt_ 222
.lisrt_ 333
.lisrt_ 333

# cat report.lis | nawk -F: '{ if($0 ~ "^BE NO:") print "report_" $2}'
report_ 111
report_ 111
report_ 222
report_ 222
report_ 333
report_ 333

My question why I cannot concate these 3 fields: "report_" $2 ".lis"
expected result is:
report_ 111.lis
report_ 111.lis
report_ 222.lis
report_ 222.lis
report_ 333.lis
report_ 333.lis

By the way, I am using Sun server for unix script.

Please help and thanks..
# 2  
Old 01-25-2008
Attach a portion of your input file as this will aid in why nawk isn't catenating the fields.
# 3  
Old 01-25-2008
The following is my input file:





Report No.: AAA

BE NO: 111

asfsdflsjdfklsdjfklsjfklsfsflsjdlk
fsdfjsfkjsklfsfj




Report No.: AAA

BE NO: 111

sdfsdfjsdklfjsfkj
fsdflkjsdfklsjkl




Report No.: AAA

BE NO: 222

dadaskdhasdjkd
dashdjkashdjhajkh




Report No.: AAA

BE NO: 222

dasdjaklsdjkladjkla
daskdjaskldjakldjklaj




Report No.: AAA

BE NO: 333

ddasdjaskldjkladjklasj
daskdjaskldjaskldj




Report No.: AAA

BE NO: 333

djakdadjaklsjdjak
dakdjakljdklajklsd

Thanks for your help
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #939
Difficulty: Easy
The author named the ping utility after the sound that a sonar makes.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Nawk coding trying to compare two fields in a file

I have a file. We can call file1. It has these contents. STOPLOSS Control_file 0000000010.000 STOPLOSS Audit_file_Signoff +0000000010.00 nawk '{ fmt="%3s %15s %15s %15s %21s\n"; if ($3==$6) { tpy="Successful Match"; jnme=$1;... (4 Replies)
Discussion started by: wawa
4 Replies

2. Shell Programming and Scripting

Concate a string in awk

Hello Community, i have a litte Problem with concating a string in an awk command. val_arr=( $( cat myfile | awk ' NR==1 { name=$2} NR==3 { dateformat=$9 OFS $6 OFS $8 OFS $7 OFS $10} NR==4 { length=$8} NR==5 { progress=int($3) } END{print name,dateformat,length,progress}; ... (6 Replies)
Discussion started by: demonking
6 Replies

3. Shell Programming and Scripting

Counting Multiple Fields with awk/nawk

I am trying to figure out a way in nawk to 1) get a count of the number of times a value appears in field 1 and 2) count each time the same value appears in field 2 for each value of field 1. So for example, if I have a text file with the following: grapes, purple apples, green squash, yellow... (2 Replies)
Discussion started by: he204035
2 Replies

4. Shell Programming and Scripting

awk /nawk :: print the everything except the first and the last fields

format of file1 "file1.txt" 1 2 3 4 A B C XX YY ZZ AA WWW The output must contain except the first and last column the output must be 2 3 B YY ZZ AA (8 Replies)
Discussion started by: centurion_13
8 Replies

5. Shell Programming and Scripting

nawk -- separation of records on basis of number of fields

A file file1.txt exists having records like The delimiter being "|" X|_|Y|_|Z|_| (number of fields 7) A|_|B|_| (number of fields 5) X|_|Z|_|H|_| (number of fields 7) A|_|D|_|S|_| (number of... (4 Replies)
Discussion started by: centurion_13
4 Replies

6. Shell Programming and Scripting

String concate problem

Hello there, I am facing the following problem in string concate. I am returning a sql column value to a shell script variable . Now when I am trying to concate the variable with another string (string appears first) I am getting a space between the two concate. Example p is the shell... (2 Replies)
Discussion started by: Pratik4891
2 Replies

7. Shell Programming and Scripting

I need help counting the fields and field separators using Nawk

I need help counting the fields and field separators using Nawk. I have a file that has multiple lines on it and I need to read the file 1 at a time and then count the fields and field separators and then store those numbers in variables. I then need to delete the first 5 fields and the blank... (3 Replies)
Discussion started by: scrappycc
3 Replies

8. Shell Programming and Scripting

concate the record

how i can bring this file into three records in my sample text file there are thre records new records always start with Data File ================================================== samle file ================================================= Data File:... (7 Replies)
Discussion started by: aboorkuma
7 Replies

9. Shell Programming and Scripting

Append tabs at the end of each line in NAWK -- varying fields

Hi, I need some help in knowing how I can append tabs at the end of each line... The data looks something like this: field1, field2, field3, field4 1 2 3 4 5 I have values in field1 and field 2 in the first row and I would like to append tab on field3 and field4 for the first row..and in... (6 Replies)
Discussion started by: madhunk
6 Replies

10. Shell Programming and Scripting

Concate all lines into one.

I have a file with 1000 records and I have to produce another file with 1 line which is a concatentation of all these records. Please help. (1 Reply)
Discussion started by: oracle8
1 Replies

Featured Tech Videos