Awk printing help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk printing help
# 1  
Old 07-29-2010
Awk printing help

Hallo,

i have a file which looks like this:

$1 $2 $3
Code:
Student1        55     Pass
                    55     Pass
                    35     Fail
Student2        55     Pass
                    55     Pass
                    35     Fail

i want that the $1 field be completely filled with respective student id;

desired output is:
Code:
Student1        55     Pass
Student1        55     Pass
Student1        35     Fail
Student2        55     Pass
Student2        55     Pass
Student2        35     Fail

Thank you!

Last edited by vgersh99; 07-29-2010 at 08:38 AM.. Reason: code tags, please!
# 2  
Old 07-29-2010
Try this:
Code:
awk '/Student/{n=$1;print;next} {print n, $0}' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 07-29-2010
Code:
nawk 'NF==3{id=$1;print;next}{print id, $0}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 07-29-2010
Code:
nawk ' NF==3{ id=$1;printf("%s\t\t%d\t%s\n", id,$2,$3);next } {printf("%s\t\t%d\t%s\n", id, $1, $2)}' file

This User Gave Thanks to steadyonabix For This Post:
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

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 awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out It is giving me an output like this...... (1 Reply)
Discussion started by: Sri3001
1 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