awk FS usage problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk FS usage problem
# 1  
Old 04-09-2011
Question awk FS usage problem

Hi All,

I have a question about the usage of FS in awk and i appreciate if you can help me sort out what i'm doing wrong.

I have a file with info ; separated and i just want to print the o/p of all fields ($1 -> $8) to the screen. As you can see it is very simple but i'm facing an error.

Below is the file (test.log) contents:

Code:
Board1;9a;60;36;60.0;60;0;0.0
Board2;96;60;35;58.3;55;0;0.0
Board3;92;60;60;100.0;60;60;100.0
Board4;8e;60;35;58.3;60;0;0.0
Board5;8a;60;35;58.3;60;0;0.0
Board6;86;60;36;60.0;60;0;0.0
Switch1;82;60;37;61.6;60;0;0.0
Switch2;84;60;37;61.6;60;0;0.0
Board9;88;60;37;61.6;60;0;0.0
Board10;8c;60;36;60.0;60;0;0.0
Board11;90;60;36;60.0;60;0;0.0
Board12;94;60;37;61.6;60;0;0.0
Board13;98;60;60;100.0;60;60;100.0
Board14;9c;60;60;100.0;60;60;100.0
SHMC;20;60;35;58.3;60;0;0.0
Alarm1;14;60;37;61.6;60;0;0.0
Alarm2;16;60;37;61.6;60;0;0.0
PEM1;c0;60;37;61.6;60;0;0.0
PEM2;c2;59;35;59.3;60;0;0.0
PEM3;c4;60;37;61.6;60;0;0.0
PEM4;c6;60;60;100.0;60;0;0.0
FAN1;c8;59;36;61.0;59;0;0.0
FAN2;ca;60;37;61.6;60;0;0.0
FAN3;cc;59;36;61.0;60;0;0.0
FAN4;ce;60;37;61.6;60;0;0.0

And here is the command i'm using just to print first field:

Code:
#awk -F ; '{print $1}' test.log

O/P:
Code:
-bash: {print $1}: command not found

Few more question, what if i want $1 o/p to have maximum of 10 characters long? what should i add to the command? when i should use printf instead of print?

Thanks in advance
# 2  
Old 04-09-2011
Try:
Code:
awk -F';' '{print $1}' test.log

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 04-09-2011
Code:
awk -F ';' '{print $1}' test.log

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 04-09-2011
Bug

Thanks for your replies, it worked with the below command (no space after -F):

Code:
awk -F';' '{print $1}' test.log

What about specifying the length of one field? ex. strict $1 value to 10 characters only.
# 5  
Old 04-09-2011
Try:
Code:
awk -F';' '{printf "%.10s\n",$1}' test.log

or
Code:
awk -F';' '{print substr($1,1,10)}' test.log

# 6  
Old 04-09-2011
Code:
awk -F\; '{print $1}' test.log

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk usage

Hi I have a file like this user="joe" phone="4280919" duration=128 login=12/02/2016 ip-address=10.230.120.35 user="mary" phone="6352728" duration=23 login=16/02/2016 ip-address=10.123.231.54 I have to convert these to as follows (csv format) (Ignore Login field)... (6 Replies)
Discussion started by: Balav
6 Replies

2. Shell Programming and Scripting

Usage of Int with NR in awk

Hello Everyone, I am new to awk and trying my hand with the diff codes and came across the below code today. It would be great if any of the Guru's help me to understand. awk '{filename = "sample_file" int((NR-1)/34) ".DAT"; print >> filename}' sample_file.DAT 34 is the no of lines each... (7 Replies)
Discussion started by: saratha14
7 Replies

3. Shell Programming and Scripting

Problem in file usage option

Hi, I have a dout in -u option in ls command. If we give ls -lt command it will dispaly the last modfied time. If we give ls -lu command it will display the last usage time of the file. My doubt here is Please refer the below commands. /appldata/rsc/dm/RejectData$ls -lt... (6 Replies)
Discussion started by: puni
6 Replies

4. Shell Programming and Scripting

problem with awk usage

I have to change the 4th feild of a line; Most of the time, the line has only 4 feilds, but sometimes, it has more than 4 feilds. I am using the below command: NEW_LINE=`echo $Line | awk '{sub ($4, "2010\\\/04\\\/07"); printf "# %-7s %9s %18s\n", $2,$3,$4}'` This works fine but if the... (7 Replies)
Discussion started by: sugan
7 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Shell Programming and Scripting

usage of underscore in awk

Hi what is the purpose of using underscore in awk. I suppose it is for defining macro's and reducing repeatation but can some one show me an example? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies

7. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

8. Programming

Problem in CPU usage

Hi all, I have C++ program that is running on linux on an ARM processor. The program is sending voice to a specific ip. When i started the program, 2 threads are running and sending voice over ip. Each of the threads are at %0.2 CPU usage which is very normal. My problem is, CPU usage is... (4 Replies)
Discussion started by: gokaytos
4 Replies

9. AIX

Netstat usage problem

Hi everyone. I need some way to map individual connections listed in netstat to PID seen by the AIX. In linux this can be done by using netstat -np. Is there a swich in AIX netstat which I have not yet found regarding this or does anyone know if "GNU" netstat has been compiled for AIX in... (1 Reply)
Discussion started by: sprellari
1 Replies

10. UNIX for Dummies Questions & Answers

AIX disk usage problem

ENV: AIX 4.3 / rs6000 while running a program our root (/) directory fills up. I simply can't find where this file is located. Doing a df . insite the program gives the following output: during run of program /dev/hd4 65536 33144 50% 953 6% / after run of program... (1 Reply)
Discussion started by: progressdll
1 Replies
Login or Register to Ask a Question