Printing using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing using awk
# 1  
Old 02-21-2012
Printing using awk

Hi
I am relatively new to awk so i am getting confused a lot
I am in need of help ... I am trying to append coloumns to the end of line using AWK

I tried using this command
Code:
awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out

It is giving me an output like this...
Code:
1002,306413,R,2009,211,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0

But I want 0's and not blank space in between Comma.

Also please tell me if there is a way if I can use variables inside the Awk By which i mean
Code:
awk -F "," '{for(s=$l;s<=217;s++);$s="0";}1' OFS=, sam_sri_out

is not working , because it is taking the value of the $l field from the file

Last edited by Franklin52; 02-21-2012 at 03:19 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-21-2012
Code:
awk -F "," '{for(s=6;s<=NF;s++){$s="0"}}1' OFS=, sam_sri_out

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing awk outputs

Hello All, I have the following command which works partially: gzcat *2016-03-25_*gz | gawk -F"|" ' BEGIN{format = "%-10s %-13s %-17s %-35s\n"; printf format, "EVENT_TYPE","RESPONSE_CODE","INTERNAL_ERR_CODE","FLOWNAME"; printf format, "----------", "-------------", "-----------------",... (6 Replies)
Discussion started by: EAGL€
6 Replies

2. Shell Programming and Scripting

Printing $values using awk

Hi All I had requirement where I need to re-order columns in a file by using a control file. here is the ctrl file c1 c2 c3 source file c3 | c1 | c2 a | b| c I should create output file based on the ctrl file columns o/p should look like this c1 | c2 | c3 b| c|a I wrote some... (9 Replies)
Discussion started by: gvkumar25
9 Replies

3. UNIX for Dummies Questions & Answers

awk printing question

im using awk as a part of my tasks to filter out stuff for reporting details in our storage environment, supposed i filtered out these details (sorry, this might be long.) bash$ > for x in 1 2; do symdg show floras0-snap$x | awk '{print $3,$4}'; done : REGULAR in GNS Yes :... (10 Replies)
Discussion started by: prodigy06
10 Replies

4. Shell Programming and Scripting

Awk printing help

Hallo, i have a file which looks like this: $1 $2 $3 Student1 55 Pass 55 Pass 35 Fail Student2 55 Pass 55 Pass 35 Fail i want that the $1 field... (3 Replies)
Discussion started by: saint2006
3 Replies

5. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

6. Shell Programming and Scripting

AWK Printing

i have a file and i want to print the second variable and add qoutes to it i do awk -F"|" '{print $2}' star.unl. i get the output xxxxxxx but i need the variable($2) to be in quotes.like "xxxxxxx" how do i do there please (3 Replies)
Discussion started by: tomjones
3 Replies

7. Shell Programming and Scripting

printing and deleting using awk

I am trying to print and delete at the same time 0KB files... using following command a-> find . -type f | xargs ls -l | awk '{ if($5 == 0) {print $0;}}' | xargs rm $0 but am not successful. Can somebody tell me how to do this ... same time I need files to be printed as well deleted later. ... (4 Replies)
Discussion started by: vivek.gkp
4 Replies

8. Shell Programming and Scripting

Doubt in awk printing

Hi awk '/print/ {print }' format.txt the above code will search for the argument "print" and displays all the lines which contain "print" from format.txt i want to print the same but with # as teh beginning For eg: format.txt contains cat dog fire current print the value of 4 print... (2 Replies)
Discussion started by: jisha
2 Replies

9. Shell Programming and Scripting

awk string printing

I am trying to print a line using awk printf command. The problem I am having is that when the string has spaces in between, it only prints the word upto the first space. For example, if my variable has "Hello World" The output is only "Hello". Here is the command I am using echo $recCtr... (2 Replies)
Discussion started by: fastgoon
2 Replies

10. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies
Login or Register to Ask a Question