AWK - Hard to understand for me


 
Thread Tools Search this Thread
# 8  
There are three double quotes on the BEGIN line
# 9  
remove the double quotes from the "SNA_DB_UP
# 10  
After removing quotes .. the below code doesn't worked for me....

Code:
BEGIN { print SNA_DB_UPG.list "|" }
{ print $8, "\t", $3}
END { print " - DONE -" }


Last edited by ambarginni; 03-16-2012 at 03:45 AM..
# 11  
what error you are geting ?

how you are executing ?
# 12  
The output is as below: (running on command prompt)

Code:
sys,root # BEGIN { print SNA_DB_UPG.list "|" }
sh: BEGIN:  not found.
sys,root # { print $8, "\t", $3}
> END { print " - DONE -" }
>

# 13  
what you actually trying to do ?

parsing any file ?

how the file looks like ?

Code:
 
awk 'BEGIN { print SNA_DB_UPG.list "|" }{ print $8, "\t", $3}END { print " - DONE -" }' filename.txt

# 14  
Thanks itkamaraj,

I have to do small change in the code (tiny project)

There is a file name SNA_DB_UPG.list which has a format:
Code:
#
#MNT4   ##R9.1.1.4
#R950   ##R9.5.0
#R9501  ##R9.5.0.1
#R960   ##R9.6.0
#############################################################
#------------MNT4-----------
MNT4|00010|msp125867|$PLATFORM_BIN/reload_PA_TABLE 1620_LM
MNT4|00020|msp127060|$PLATFORM_BIN/reload_PA_TABLE 1626_LMT
#------------R950-----------
R950|00010|msp126597|$PLATFORM_BIN/reload_PA_TABLE 1830PSS_32
R950|00020|msp126860|$PLATFORM_BIN/reload_ctl neModifier
R950|00030|msp126856|$UPG_BIN_DIR/cv950_SNAupg_001.sh
#------------R9501-----------
R9501|00010|msp127217|$PLATFORM_BIN/reload_ctl neModifier
R9501|00020|msp127540|$PLATFORM_BIN/reload_ctl layerRateMap
R9501|00030|msp127060|$PLATFORM_BIN/reload_PA_TABLE 1626_LMT
#------------R960-----------
R960|00010|msp131228|$PLATFORM_BIN/reload_ctl neModifier
R960|00020|msp131233|$UPG_BIN_DIR/cv960_NWCupg_001.sh

From here I need to read this file and create two seperate file say SPEC_INSTR.list
Code:
MNT4|00010|msp125867|$PLATFORM_BIN/reload_PA_TABLE 1620_LM
MNT4|00020|msp127060|$PLATFORM_BIN/reload_PA_TABLE 1626_LMT
R950|00010|msp126597|$PLATFORM_BIN/reload_PA_TABLE 1830PSS_32
R950|00020|msp126860|$PLATFORM_BIN/reload_ctl neModifier
R950|00030|msp126856|$UPG_BIN_DIR/cv950_SNAupg_001.sh
R9501|00010|msp127217|$PLATFORM_BIN/reload_ctl neModifier
R9501|00020|msp127540|$PLATFORM_BIN/reload_ctl layerRateMap
R9501|00030|msp127060|$PLATFORM_BIN/reload_PA_TABLE 1626_LMT
R960|00010|msp131228|$PLATFORM_BIN/reload_ctl neModifier
R960|00020|msp131233|$UPG_BIN_DIR/cv960_NWCupg_001.sh

and the other file with DISTINCT_MODEL.list
Code:
$PLATFORM_BIN/reload_PA_TABLE 1620_LM
$PLATFORM_BIN/reload_PA_TABLE 1626_LMT
$PLATFORM_BIN/reload_PA_TABLE 1830PSS_32
$PLATFORM_BIN/reload_ctl neModifier
$UPG_BIN_DIR/cv950_SNAupg_001.sh
$PLATFORM_BIN/reload_ctl neModifier (remove it - only distinct)
$PLATFORM_BIN/reload_ctl layerRateMap
$PLATFORM_BIN/reload_PA_TABLE 1626_LMT (remove it - only distinct)
$PLATFORM_BIN/reload_ctl neModifier (remove it - only distinct)
$UPG_BIN_DIR/cv960_NWCupg_001.sh

After this I need to execute the SPEC_INSTR.list first command/line i.e.
Code:
MNT4|00010|msp125867|$PLATFORM_BIN/reload_PA_TABLE 1620_LM

Only If the fourth field i.e.
Code:
$PLATFORM_BIN/reload_PA_TABLE 1620_LM

is present in the SPEC_INSTR.list file. If present after executing this command we need to delete the entry of 1620_LM from the SPEC_INSTR.list file
and further execute the same until the last command/line of the SPEC_INSTR.list file.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #256
Difficulty: Easy
MILNET gave birth to NIPRNet, which was used to transmit sensitive but unclassified data between internal users and also provide those users with a gateway to the commercial Internet.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help understand awk command

Help understand awk command This command converts the column values to rows. Command: awk -s1=" " '{S=S?S OFS s1 $0 s1:s1 $0 s1} END{print S}' OFS=, Input_file Example: 1 2 3 is converted to: 1, 2, 3 Can anyone please help me understand this command? Please use code tags when... (1 Reply)
Discussion started by: mohan44
1 Replies

2. Shell Programming and Scripting

(hard one) awk, copy matching 2 col & 10-12 rows, is it possible?

Hey guys, my first post here. I'm trying to use awk to copy all matching paragraphs from one file The file looks like this : Test Case Number 990990003099 Card Type CCCC Transaction Type Sale Entry Mode Keyed Account Number 4099562299219923 Transaction Amount 78.88 Description lorem... (2 Replies)
Discussion started by: awkawed
2 Replies

3. UNIX for Dummies Questions & Answers

Unable to understand awk script.

Hi below is the samll awk script which i am not able to understand properly. here a bit confusion in 2nd line for me 1. why *\ is not used before . in second line as it was used in first line *\$*\. */ 2. why always \ is used in every first line 3. is there any specific meaning... (9 Replies)
Discussion started by: scriptor
9 Replies

4. Shell Programming and Scripting

awk doesn't understand 'read' statement!!!

While working on awk programming, i found that it doesn't understand 'read' statement. Then what's the use of 'continue' and 'break' statement in awk. For ex: awk '{k=1; while (k<10) {print $0; k++}}' emp.lst Now, please say if I want to put the logic that after priting 1 line, it will ask for... (13 Replies)
Discussion started by: ravisingh
13 Replies

5. Shell Programming and Scripting

Don't understand AWK asort behaviour

Hello, I have the following script : BEGIN { print "1 ***"; split("abc",T,""); T="e"; T="z"; T="y"; for (i in T) printf("%i:%s ",i,T); print ""; for (i=1; i<=length(T); i++) printf(T); print "" print "2 ***"; asort(T,U); for (i in U) printf("%i:%s ",i,U); ... (3 Replies)
Discussion started by: jgilot
3 Replies

6. Shell Programming and Scripting

Need help to understand Awk code.

Hi Guys, Can someone please explain this code to me. I could figure out it's adding and comparing two fields but I am not sure which ones. sort -t"|" -k3.1 /tmp/mpcashqc.xtr| awk -F"|" '{CHECKAMT+=$3;BATCHTOT=$4;\ items++}END{for(i in CHECKAMT) if (CHECKAMT!=BATCHTOT)... (6 Replies)
Discussion started by: nua7
6 Replies

7. Shell Programming and Scripting

Don't understand how RS functions in awk

I learn using RS in awk to extract portion of file in this forum which is wonderful solution to the problem. However, I don't understand how exactly it operates. I don't quite understand the mechanism behind how searching for /DATA2/ can result in extracting the whole section under "DATA2" ... (3 Replies)
Discussion started by: joe228
3 Replies

8. UNIX for Dummies Questions & Answers

unable to understand a awk code

i am not able to understand the following code for awk: $awk -F"|" '{ kount++} >END { for (desig in kount) > print desig,kount }' emp.list the input file i.e. emp.list is :: 3432| p.k.agrwal |g.m |sales 4566|g.l.sharma |director|production 3433|r shah | g.m | production... (1 Reply)
Discussion started by: streetfi8er
1 Replies

9. UNIX for Dummies Questions & Answers

Unable to understand associative nature of awk arrays

About associative nature of awk arrays i'm still confused, not able to understand yet how array element can be accessed based on a string, I got one example at gawk manual to illustrate associative nature of awk arrays, it goes here: Codeawk ' # Print list of word frequencies { for (i = 1;... (3 Replies)
Discussion started by: nervous
3 Replies

10. Filesystems, Disks and Memory

The best partitioning schem for a 250GB Sata hard drive & a 75GB SCSI hard drive

Hi I have 2 75GB SCSI hard drives and 2 250GB SATA hard drives which are using RAID Level 1 respectively. I wana have both FTP and Apache installed on them as services. I'm wondering what's the best partitioning schem? I wana use FC3 as my OS, so, I thought I can use the 75GB hard drive as the /... (0 Replies)
Discussion started by: sirbijan
0 Replies

Featured Tech Videos