Problem with formatting text with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with formatting text with awk
# 1  
Old 11-29-2011
Problem with formatting text with awk

I want the following output:

Code:
User ID:     4071
Last Name: Gills
First Name: Roberts
Address:     Maple Dr.
Phone#:     702346789

from this command:

Code:
grep "$uId" database.txt | awk -F":" '{print "User ID:\t"$uId"\nLast Name:\t"$lname"\n...etc. }'

But all I get is this:

Code:
User ID:     4071:Gills:Roberts:Maple Dr.:702346789
Last Name: 4071:Gills:Roberts:Maple Dr.:702346789
First Name: 4071:Gills:Roberts:Maple Dr.:702346789
Address:     4071:Gills:Roberts:Maple Dr.:702346789
Phone#:     4071:Gills:Roberts:Maple Dr.:702346789


What is up?
# 2  
Old 11-29-2011
Isn't it:
Code:
# Awk indexed by number
grep "$uId" database.txt | awk -F":" '{print "User ID:\t"$1"\nLast Name:\t"$2"\netc ..."}'

# Example:
# echo "4071:Gills:Roberts:Maple Dr.:702346789" | awk -F":" '{
print "User ID:\t" $1
print "Last Name:\t" $2
print "First Name:\t" $3
print "Address:\t" $4
print "Phone#:\t\t" $5
}'
User ID:        4071
Last Name:      Gills
First Name:     Roberts
Address:        Maple Dr.
Phone#:         702346789

# Your command must be:
# grep "$uId" database.txt | \
awk -F":" '{
			print "User ID:\t" $1 
			print "Last Name:\t" $2
			print "First Name:\t" $3
			print "Address:\t" $4
			print "Phone#:\t\t" $5
		}'

Try to check awk's functions: printf and sprintf!

Last edited by felipe.vinturin; 11-29-2011 at 02:57 PM..
# 3  
Old 11-29-2011
Still having the same problem.
# 4  
Old 11-30-2011
can u post the sample input file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk problem underlining text

I have a whole text file filled with titles of books and its writers and the publications houses etc. Example: I want to underline the title:" This business of the Gods". An awk line can do the trick, but I have not been able to get it together. I am close but I can't make it work. (7 Replies)
Discussion started by: TheoDore4
7 Replies

2. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies

3. Shell Programming and Scripting

Complex text parsing with speed/performance problem (awk solution?)

I have 1.6 GB (and growing) of files with needed data between the 11th and 34th line (inclusive) of the second column of comma delimited files. There is also a lot of stray white space in the file that needs to be trimmed. They have DOS-like end of lines. I need to transpose the 11th through... (13 Replies)
Discussion started by: Michael Stora
13 Replies

4. Shell Programming and Scripting

Help Me with the formatting of text

Hi, I am new to this forum; I need a help for my scripting problem. I have made a script in Unix which is extracting a report but the issue is that report is not in a proper format. Original Report Ex: Field 1....................... a b c d e f g Field 2............. @ID.@ID Field... (4 Replies)
Discussion started by: tush
4 Replies

5. Shell Programming and Scripting

Text formatting help

I have bunch of files with data's like below. archive.log.0104 ar0104_akl ar0731_rln ar0731_rsl M70148I need to compile all those files into a single file(.xls file) in the below format. 1st row is file name - should come in 1st column in excel In 2 - 4 row, all entries starts with... (13 Replies)
Discussion started by: vasanth_123
13 Replies

6. Shell Programming and Scripting

Help with Text formatting

I am generating the o/p as: BLANSWER 112747 112747 TBLQSTN 983 692 INITIATIVE 35 35 PAIGN 3122 3538 IGNCONTACT 90136 93534 IGNGROUP 27 27 AIGNSTEP 16899 20437 AIGNTYPE ... (1 Reply)
Discussion started by: karumudi7
1 Replies

7. Shell Programming and Scripting

Text formatting

A folder is having n number of files each file is having column names in it .Hence using below code . for file in /xxx/sss/* do filename=$( basename $file ) sed -e '1,2d; $d; /^*$/d; /selected\.$/d' ${file} | \ sed -e '1s/^/INSERT INTO '${filename}' VALUES (/; $!s/$/,/; $s/$/);/'... (6 Replies)
Discussion started by: rocking77
6 Replies

8. UNIX for Dummies Questions & Answers

Formatting TEXT

Hello, I have the following lines in a text file: /var/spool/postfix/defer/1/15C86B0547C /var/spool/postfix/defer/1/19AD1B054A2 /var/spool/postfix/defer/2/25A16B05493 /var/spool/postfix/defer/6/626FBB05496 /var/spool/postfix/defer/6/634D4B0544A /var/spool/postfix/defer/6/6A8ACB05499... (2 Replies)
Discussion started by: mojoman
2 Replies

9. Shell Programming and Scripting

AWK Formatting Problem

Hi All, I'm having a problem with the way awk is interperting a space between double quotes in a for loop. Below is the code and output from running the script: AWK for loop: for i in $(awk 'BEGIN{FS=","}{print "Probe Name:" $1};{print "Probe Temp:" $2};{ print... (2 Replies)
Discussion started by: cstovall
2 Replies

10. Shell Programming and Scripting

formatting text

Hi, I am having a file containing entries like: .iso.org.dod.internet.mgmt.mib-2.system.sysName.0 .iso.org.dod.internet.mgmt.mib-2.system.sysLocation.0 .iso.org.dod.internet.mgmt.mib-2.system.sysServices.0 .iso.org.dod.internet.mgmt.mib-2.system.sysORLastChange.0... (16 Replies)
Discussion started by: esham
16 Replies
Login or Register to Ask a Question