help with awk delimited by |~| in a record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with awk delimited by |~| in a record
# 8  
Old 04-06-2008
Thanks ERA and MATRIXMADHAN.

/usr/local/bin/awk -F"CARDDESC=" '{ split($2, arr, "|"); print arr[1] }' t1
A8T1

now would you be kind enough try to explain what it really did.

I have gone with what matrixmadhan recommended

Peace !!!
# 9  
Old 04-06-2008
Quote:
Originally Posted by era
Whoever devised that particular file format should be taken out and shot.
sometimes, delimiters need to be unique so that it won't get mixed up with actual data in the fields. therefore, you shouldn't jump to conclusions like this Smilie
# 10  
Old 04-06-2008
just another way
Code:
awk -F'[|~=]' '
{
 for ( i =1; i<=NF;i++ ) {
   if ( $i ~ /CARDDESC/ ) {
    print $(i+1)
   }
 }
}' file

# 11  
Old 04-06-2008
Another possibility with sed:

Code:
sed 's/.*ARDDESC=\([^|]*\).*/\1/'

Regards
# 12  
Old 04-06-2008
Quote:
Originally Posted by knijjar
Thanks ERA and MATRIXMADHAN.

/usr/local/bin/awk -F"CARDDESC=" '{ split($2, arr, "|"); print arr[1] }' t1
A8T1

now would you be kind enough try to explain what it really did.

I have gone with what matrixmadhan recommended

Peace !!!

here the field delimiter is CARDDESC=
and within that split the second field ($2) with delimiter as "|" - result is populated in array arr.

Now the result is available at first field of the array
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a header record (tab delimited) in multiple files

Hi Forum. I'm struggling to find a solution for the following issue. I have multiple files a1.txt, a2.txt, a3.txt, etc. and I would like to insert a tab-delimited header record at the beginning of each of the files. This is my code so far but it's not working as expected. for i in... (2 Replies)
Discussion started by: pchang
2 Replies

2. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

3. Shell Programming and Scripting

awk read one delimited file, search another delimited file

Hello folks, I have another doozy. I have two files. The first file has four fields in it. These four fields map to different locations in my second file. What I want to do is read the master file (file 2 - 23 fields) and compare each line against each record in file 1. If I get a match in all four... (4 Replies)
Discussion started by: dagamier
4 Replies

4. Shell Programming and Scripting

How to make delimited record ????

Can anyone suggest how to make delimited data for below report format Member Nbr Member Name Date Date Number Miles Rejected Reason Purge 1000000000 BROWNS N/B 10121998 01121998 377393930 500 INVALID CUSTOMER NUM issue is that my column name, data and between column i have variable... (7 Replies)
Discussion started by: ns64110
7 Replies

5. Shell Programming and Scripting

Use awk or sed to parse delimited string

Hi I am trying to figure out the best way to search a long log file and print out certain information. For example if I had a line in a log file delimited by ampersand first_name=mike&last_name=smith&zip_code=55555&phone=555-5555&state=ma&city=boston and I only wanted to search for and... (3 Replies)
Discussion started by: mstefaniak
3 Replies

6. Shell Programming and Scripting

awk help - delimited file

Hi, I have a delimited file with 10 fields. I have to replace a character in field 1 and field 5. It is possible to do using awk where i can read a row at a time field by field and if the field value is 1 or 5 then i will replace the character. But this operation is cumbersome since the... (8 Replies)
Discussion started by: ashwin3086
8 Replies

7. Shell Programming and Scripting

Using AWK to parse a delimited field

Hi everyone! How can I parse a delimited field using AWK? For example, if I have lastName#firstName or lastName*firstName. I'd like an AWK script that would return lastName and then another that would return firstName? Is this possible? (13 Replies)
Discussion started by: Fatbob
13 Replies

8. Red Hat

Counting columns in a delimited record with NULLs

I am trying to count the number of columns in a delimited flat file. The record is tab delimited. When I use the command wc -w, I am getting unexpected results when the record contains a NULL value. I believe it is because there is a "word" missing. The below example will return 4 words... (2 Replies)
Discussion started by: nmalencia
2 Replies

9. Shell Programming and Scripting

splitting tab-delimited file with awk

Hi all, I need help to split a tab-delimited list into separate files by the filename-field. The list is already sorted ascendingly by filename, an example list would look like this; filename001 word1 word2 filename001 word3 word4 filename002 word1 word2 filename002 word3 word4... (4 Replies)
Discussion started by: perkele
4 Replies

10. UNIX for Advanced & Expert Users

awk - delimited output

Hi I am looking for syntax in awk, where I am printing comma separated coulmns read from delimited file. Say for e.g. awk -F":" '{print $1","$2","9}' fname Instead of using "," withing print syntax,is there any way by which fields being printed will automatically get delimited by comma? ... (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question