awk printf in required format


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk printf in required format
# 1  
Old 11-14-2011
awk printf in required format

Hi

my awk variable $0 contains the below data
Code:
Input file
000001  The Data
000002* The line 2
000003* The line3

Code:
output file Req
000001*  The Data
000002** The line 2
000003** The line3

one * at column seven needs to be appended to the  input lines,

# 2  
Old 11-14-2011
Expecting this ...
Code:
$ awk '{print $1"*",$2,$3}' infile

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 11-14-2011
thanks jayan and thanks alot to all the unix forum users, really great help

this is the actual code by vgersh , https://www.unix.com/302572282-post21.html
Code:
iam want to get the output in 
printf("*%s\n%s\n", f2[FNR],$0)

000001* this is line 1
000002** this is line2

how can we break the f2[FNR], can we use regular expressions in awk because in my case the first 6 characters are numeric or spaces
# 4  
Old 11-14-2011
Quote:
Originally Posted by rakeshkumar
thanks jayan and thanks alot to all the unix forum users, really great help

this is the actual code by vgersh , https://www.unix.com/302572282-post21.html
Code:
iam want to get the output in 
printf("*%s\n%s\n", f2[FNR],$0)

000001* this is line 1
000002** this is line2

how can we break the f2[FNR], can we use regular expressions in awk because in my case the first 6 characters are numeric or spaces
Hmm... I don't follow what you actually want. Is this it?:
Code:
sub(space, "*&", f2[FNR])
sub(space, "**&")
printf("%s\n%s\n", f2[FNR],$0)


Last edited by vgersh99; 11-14-2011 at 11:46 AM..
# 5  
Old 11-14-2011
Code:
my input line is 
000001  this is line1
printf("*%s",f2[FNR]); this prints below output
*000001  this is line 1
## but i want to format the output like ##
000001* this is line1
FYI : 1 to 6 columns contains line numbers , * at 7th column means code is commented.

# 6  
Old 11-14-2011
Quote:
Originally Posted by rakeshkumar
Code:
my input line is 
000001  this is line1
printf("*%s",f2[FNR]); this prints below output
*000001  this is line 1
## but i want to format the output like ##
000001* this is line1
FYI : 1 to 6 columns contains line numbers , * at 7th column means code is commented.

Check the code posted previously for you previously mentioned thread - it does what you're after.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required in printing in specific format

Hi All, I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields. I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width... (4 Replies)
Discussion started by: shash
4 Replies

2. Shell Programming and Scripting

Need help to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

3. Shell Programming and Scripting

Not able to convert the second column to required format

I have this file 103,7243534512111,NiaC1-02 105,720412845543550,NiaC2-00 105,720439254543351,NiaC200 105,720445724354315,Nia100 105,72044770454398,Nia100 105,720484154334546,Nia616 i want in this format insert into aildump values(103,'7243534512111','NiaC1-02'); I'm able to... (3 Replies)
Discussion started by: nikhil jain
3 Replies

4. Shell Programming and Scripting

printf format with awk

Hello Here is an easy one Data file 12345 (tab) Some text (tab) 53.432 23456 (tab) Some longer text (tab) 933.422 34567 (tab) Some different text (tab) 29.309 I need to awk these three tab-delimited columns so that the first two are unchanged (unformatted) and the third shows two decimal... (1 Reply)
Discussion started by: palex
1 Replies

5. Shell Programming and Scripting

awk printf format in columns

Hi all, i have written this script: awk -F';' ' BEGIN { printf "\n" printf "\n" printf "\n" printf "----------------------------------------------\n" print " For test " printf "----------------------------------------------\n" test_200 = 0 test_300 = 0 test_500 = 0 test_1000 = 0... (11 Replies)
Discussion started by: arrals_vl
11 Replies

6. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

7. Shell Programming and Scripting

printf to format lines.

Hey, I'm trying to read printf(3) and seems I need to use the * WIDTH but I'm not quite sure how to go about it. there needs to be 3 fields per line, the lines read in from file looks like this: JUICE - APPLE:JUST JUICE:7 MILK - CHOCOLATE:BREAKA:7 this needs to be output backwards with... (6 Replies)
Discussion started by: gcampton
6 Replies

8. Shell Programming and Scripting

How to format the output using float in awk{printf}

Hi I'm using awk to manipulate the data in the 6th field of the file xxx_yyy.hrv. The sample data that is available in this field is given below 220731.7100000000000000 When i tried using this command cat xxx_yyy.hrv | awk '{printf("%23.16f\n",$6*-1)}' I get the output as... (4 Replies)
Discussion started by: angelarosh
4 Replies

9. Shell Programming and Scripting

awk printf formatting using string format specifier.

Hi all, My simple AWK code does C = A - B If C can be a negative number, how awk printf formating handles it using string format specifier. Thanks in advance Kanu :confused: (9 Replies)
Discussion started by: kanu_pathak
9 Replies

10. Shell Programming and Scripting

printf format

hi, i would like to extract the header and put it in a variable, then use printf to output the variable, but i keep on getting errors...please tell me if my format is incorrect. HDR = "`ps -e -o user,pid,ppid,pcpu,stime,etime,time,comm | head -n 1`" printf (%s, $HDR); thanks! (3 Replies)
Discussion started by: laila63
3 Replies
Login or Register to Ask a Question