awk string printing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk string printing
# 1  
Old 10-30-2006
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 ${f4} ${f5} ${f6} ${f7} |\
awk '{printf "%3d %-22s %5d %-22s %-250s\n", $1, $2, $3, $4, $5 }' >>$REPORT

here ${f7} is a field that is a sentence.

Can Someone help me to print the whole sentence without truncating at the first space?

Thanks
# 2  
Old 10-30-2006
Code:
echo $recCtr ${f4} ${f5} ${f6} ${f7} |\
awk '{str=$5;for(i=6;i<=NF;++i) str=str FS $i; printf "%3d %-22s %5d %-22s %-250s\n", $1, $2, $3, $4, str }' >>$REPORT

# 3  
Old 10-30-2006
why no just use /usr/bin/printf and keep it in shell, quoting the variables...like this:
Code:
/usr/bin/printf "%3d %-22s %5d %-22s %-250s\n" "${f4}" "${f5}" "${f6}" "${f7}" >>$REPORT

You are aware that you are printing five fields and only supplying four right?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Help printing string

Hi, I have a file containing many times the word "IPaddress". and i need a command that finds that string or word and print it only once. I've tried the following but they print a line for each match: grep "IPaddress" /directory/file.xml find . | xargs grep 'IPaddress' -sl i have many... (2 Replies)
Discussion started by: blacksteel1988
2 Replies

3. Shell Programming and Scripting

Printing the lines of the string with highest value

Please help . The script need to first grep for all lines with "C:" as it contains a value Here the value is 0 1,00: This , is a good script c:0 and then give output of the lines with top 3 highest value for c: 1,00: This , is a nice script c:9999 1,00: This , is a... (3 Replies)
Discussion started by: necro98
3 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Programming

Printing same strIng many times

In python how we need to print a same string many times without using loop. I cane across something like * operator for this . How we Can use this in a print statement ? I am using python 3.x Please help me (7 Replies)
Discussion started by: pandeesh
7 Replies

6. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

7. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

8. UNIX for Dummies Questions & Answers

Printing a part of a string

hi I have the input as follows ABC =893 JKL = "jee" alias PQR = 9833 alias STUVE = "kuiue" I should be able to print as follows ABC JKL alias PQR alias STUVE Thanks Suresh (7 Replies)
Discussion started by: ssuresh1999
7 Replies

9. UNIX for Dummies Questions & Answers

Perl, printing a string into columns

How can I use Perl to a take a string of 10 characters and print the last five characters of the string in columns 1-5 and the first five in columns 6-10? Result: 0123456789 5 0 6 1 7 2 8 3 9 4 (5 Replies)
Discussion started by: doubleminus
5 Replies
Login or Register to Ask a Question