Loosing formatting when echoing an awk script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Loosing formatting when echoing an awk script
# 1  
Old 03-23-2010
Loosing formatting when echoing an awk script

1. The problem statement, all variables and given/known data:
When I echo out the output of my awk script I loose the formatting
that I set in my awk script (it should be in a table format).


2. Relevant commands, code, scripts, algorithms:



3. The attempts at a solution (include all code and scripts):
Code:
 
set dir = $1
    foreach file ($dir/*)
        set output =  `awk -f /home/alex/Desktop/aal $file `
        echo $output
        printf "\n"
    end

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Why?
Southampton University, UK, Paul Lewis, G400
# 2  
Old 03-23-2010
Quote:
Originally Posted by ROFL
1. The problem statement, all variables and given/known data:
When I echo out the output of my awk script I lose the formatting
that I set in my awk script (it should be in a table format).
You don't need to save it into a variable at all. If you don't redirect it, the code will print to the stdout of your script without interference.
Code:
set dir = $1
    foreach file ($dir/*)
        awk -f /home/alex/Desktop/aal $file
        printf "\n"
    end

It's messing up your formatting because of how your shell processes text before feeding it into echo, splitting things apart on whitespace etc. The answer is to not do that. Smilie
Quote:
Why?
Southampton University, UK, Paul Lewis, G400
Something to do with proving your intentions I think. We've had quite a lot of people use these forums to cheat. At least homework's not banned entirely anymore, hm? Smilie

Last edited by Corona688; 03-23-2010 at 11:38 AM..
# 3  
Old 03-23-2010
Thank you very much. Yes, I wasn't aware you could call commands directly - it is the first shell script I've ever written you see and my lecturer is useless.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

echoing complex awk command into file fails

Using hp-ux's shell, I'm trying to echo a complex awk command into a script file for later use. But it fails on a newline character and splits the rest of the command onto the next line. echo ' printf("%s: TOTAL = %18.0lf\n", FILENAME, TOTAL) >> "TOTAL.TXT";' >>awk.script Looks... (3 Replies)
Discussion started by: Scottie1954
3 Replies

3. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

4. UNIX for Dummies Questions & Answers

awk formatting

Hi all, I'm writing a simple awk code: awk 'BEGIN {FS="|"};{print "Type\tNumber\ttypes\tTotal";};{print $1, "\t", $2, "\t", $3, "\t", $4, "\t";}' db_query.txt it gives me the result: Type Number types Total XXX 498.0 5100.0 5274.661 Type Number types Total... (7 Replies)
Discussion started by: messi777
7 Replies

5. Shell Programming and Scripting

AWK formatting help.

Dear all I require help with AWK regarding this situation Input is : fn1 12345 fn1 23456 fn3 231513 fn1 22325 fn3 123125 Desired output is fn1 12345 23456 22325 fn3 231513 123125 (5 Replies)
Discussion started by: Peasant
5 Replies

6. UNIX for Advanced & Expert Users

Argumenting passed not echoing inside the script

Hi I have a program test.ksh #! /bin/ksh echo $1 echo $2 when i run this from command line like ksh test.ksh abc def Its echoing the passed arguments correctly where as if i run form commadn line like test.ksh abc def its not echoing the parameters saying like test.ksh not found.But i... (4 Replies)
Discussion started by: sathish.shanmug
4 Replies

7. What is on Your Mind?

You know your on the brink of loosing it when.....

you spend an entire day with scripting nightmares and go to bed real late in the early morning hrs to wake up to your gf asking you a question and your only answer is "It's in the script" LMAO Happened to me this morning would you believe that?? My daughter is 10yrs old and my gf wanted to check... (3 Replies)
Discussion started by: phpfreak
3 Replies

8. Shell Programming and Scripting

awk script formatting

Hello, I have got the following kine in my script awk '{printf("%s,", $0);next}{printf("%s", $0)}' ORS="," a.txt > b.out The contents of b looks somewaht like this: QUEUE(QUEUE1.Q),CURDEPTH(0),QUEUE(QUEUE2.Q),CURDEPTH(0),QUEUE(QUEUE3.Q),CURDEPTH(0) But my desired output is :... (10 Replies)
Discussion started by: King Nothing
10 Replies

9. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies

10. Shell Programming and Scripting

Formatting using awk

Let's say I write a simple script that contains the following: date | awk '{print $1}' date | awk '{print $2}' Of course, when I run the script the output will look similar to: Tue Mar What if I want my ouput to be on one line as follows: Tue Mar What changes would I need to... (2 Replies)
Discussion started by: cdunavent
2 Replies
Login or Register to Ask a Question