Operating System - Linux
1828359 Members
3061 Online
109976 Solutions
New Discussion

Re: Problem to newline change

 
SOLVED
Go to solution
Dummy_Guy
Advisor

Problem to newline change

Hi all,
I have a very frustrate problem.
My input file time.txt is:
mfg pts/tu Fri Sep 30 15:24
mfg pts/tu Fri Sep 30 15:24
mfg pts/tGb Mon Sep 26 09:01

And my script I wrote
LTIME=$(more /tmp/time.txt |uniq |awk '{print $4 " " $5 " " $6 ","}')

If I do this in script I get
LTIME = Sep 30 15:24,
Sep 26 09:01,

If I manually run in Unix prompt, I get
LTIME = Sep 30 15:24, Sep 26 09:01,

How can I get the script having the same output as it is in Unit prompt? (I don't want the newline)
3 REPLIES 3
saju_2
Respected Contributor
Solution

Re: Problem to newline change

Hi

Instead of the print u give printf and try. :)

Reagrds
CS
Howard Marshall
Regular Advisor

Re: Problem to newline change

John,

I'm not sure what you mean. When I type the LTIME command just as you have it written (only the data file name is changed) then echo $LTIME I get coma separated output on one line.

When I put it in a script and echo $LTIME from the script I get coma separated output on one line.

I get the same output printed either way.

On a side note though, more is an interactive program, you may get faster results from cat or in this case just

Uniq /tmp/time.txt | awk '{#stuff}'

However, if you want to make certain that there are no new lines in the output printf may be the way to go

Awk '{ printf "%s %s %s, ",$4,$5,$6 }'

The reason this will work and print will not is that print always puts a new line on the end of its string and with printf if you want a new line, you have to put it in manually. Otherwise it will keep stacking onto the same line.

Hope this helps some

H
Dummy_Guy
Advisor

Re: Problem to newline change

I found the solution Thank you...

printf does work...