awk producing too many fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk producing too many fields
# 1  
Old 10-30-2013
awk producing too many fields

Hey guys, awk is putting out too many results, two of each specifically. See below.

Code:
Code:
read CPU_VENDOR_ID <<< $(cat /proc/cpuinfo | grep "vendor_id" | awk -F: '{print $2}')
echo $CPU_VENDOR_ID
echo

Output:
Code:
AuthenticAMD AuthenticAMD

I only want it to print out "AuthenticAMD" once.

What am I doing wrong here?
# 2  
Old 10-30-2013
How many processors/cores do you have?

Last edited by RudiC; 10-30-2013 at 09:32 AM.. Reason: typos typos typos!
# 3  
Old 10-30-2013
2 cores, Dual-Core AMD Athlon 2 N330
# 4  
Old 10-30-2013
That's why! use uniq or sort -u.
# 5  
Old 10-30-2013
Ah, yeah, kicking myself slightly lol. Thanks dude
# 6  
Old 10-30-2013
Hi,
You must say from "grep" to stop research when it found first occurence.
under gnu grep (eg linux):
Code:
read CPU_VENDOR_ID <<< $(cat /proc/cpuinfo | grep -m 1 "vendor_id" | awk -F: '{print $2}')

Regards.
# 7  
Old 10-30-2013
You may try like this without awk

Code:
$ grep -Pom 1 '^vendor_id\s*:\s*\K.*' /proc/cpuinfo
GenuineIntel

Code:
read CPU_VENDOR_ID <<<$(grep -Pom 1 '^vendor_id\s*:\s*\K.*'   /proc/cpuinfo)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script not producing output

Hi, I have a text file with some thousands of rows of the following kind (this will be referred to as the inputFileWithColorsAndNumbers.txt): Blue 6 Red 4 Blue 3 Yellow 4 Red 7 Colors in the left column and a number in the right one for each line. I want to run an awk... (5 Replies)
Discussion started by: Zooma
5 Replies

2. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

3. Shell Programming and Scripting

Csh arithmetic not producing the expected value

My original post did not show up properly. I am trying again. I have a simple tsch script that does some basic arithmetic. The calculated value was not producing the result I was expecting. I wrote a sample script to illustrate the things that I tried. #!/bin/tcsh @ count = 43 @... (3 Replies)
Discussion started by: sgualandri
3 Replies

4. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

5. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

6. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

7. IP Networking

Tcpdump -i any producing duplicate packages?

Hi, Can anyone explain why do I see same request twice in tcpdump package when I use "tcpdump -i any"? So I'm tracing packets on eth1.800 interface, but using "tcpdump -i any" to capture them. What I see is that the requests/responses from my side seem to appear as duplicate in the pcap file,... (1 Reply)
Discussion started by: Juha
1 Replies

8. Shell Programming and Scripting

Help, while loop and sed not producing desired output

Hello everyone, I need some assistance with what I thought would have been a very simple script. Purpose of Script: Script will parse through a source file and modify (search/replace) certain patterns and output to stdout or a file. Script will utilize a "control file" which will contain... (12 Replies)
Discussion started by: packetjockey
12 Replies

9. Shell Programming and Scripting

Script not working...producing 0's and not number

Below is my script: #!/bin/sh #echo "Please type oracle-lower case please:" #read X #if ] #then # echo "Sorry that is not oracle, try again" # exit 1 #else # echo Thank you #fi find / -name oracle 2>/dev/null | while read line do bdf 2>/dev/null |... (6 Replies)
Discussion started by: bigben1220
6 Replies

10. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies
Login or Register to Ask a Question