Hi,
when i am executing this script, i am getting the values of TID and Intime in different lines.
How can i print both output values in a single line. please advise
_____________________________
#!/bin/ksh
export Path="/abc/def/ghi";
Home="/abc/jkl/prt";
cd $Path
cat $Home | while read line
do
TID=$(echo $line|awk '{print $4}');
Intime=$(ls -ltr | grep $TID | awk '{print $8}')
print $line
print $Intime
done
______________
Output : Prateek
12:15
Desired outpt : Prateek 12:15
------------------
Thanks in Advance
well, the option i know is use "echo" instead of print
and use the option "-n" to tell echo not to output a new line
replace
print $line
print $Intime
for
echo -n $line
echo $Intime
buuut, that script looks really, hmmm, is like using "cat file | grep something"
i strongly suggest you stop using awk in that manner
also, exporting a variable called HOME and one called PATH is not really smart ....
also, not cheking if the cd worked can be dangerous (i know a guy that used cd and then deleted all the files in that folder, but the cd didnt worked and he deleted the /bin folder)
|| means, "if the previos command failled, execute this", is the oposite of && that means "if the previous command ended ok do this"
feeding the while from below is faster and cleaner
awk can output adta, dont need to create a variable (and use memory and cpu cycles)
printf works pretty much liek the c analog, and if you want a new line, you have to tell awk to do so (in the second printf , the \n)
BEWARE, im doing this blindly in the forum, so check it out for simple syntax errors
if you need more info, read this,. is like my bible when it comes to scripting
Advanced Bash-Scripting Guide
i also noticed that you use ksh
any reason to do so?
any ways, that bash "manual" is still good :P
Concur with broli that the script can probably be refactored to make better use of awk.
I'm not sure I really grasp what TID is supposed to be, so you might want to change t[$4] to something else. I assumed TID will be the fourth field in the file $Home. (Less weird variable names would help, too.)
here is what i want to achieve.. i have a file with below contents
cat fileName
blah blah blah
.
.DROP this
REJECT that
.
--sport 7800 -j REJECT --reject-with icmp-port-unreachable
--dport 7800 -j REJECT --reject-with icmp-port-unreachable
.
.
.
more blah blah blah
--dport 3306... (14 Replies)
I have a file in unix with sample data as follows :
--------------------------------------------------------------
--------------------------------------------------------------
{30001002|XXparameter|Layout|$
I want this file to be splitted into different files and corresponding to the sample... (54 Replies)
Hi,
I have a requirement with,
No~Dt~Notes
1~2011/08/1~"aaa
bbb
ccc
ddd
eee
fff
ggg
hhh"
Single column alone got splitted into multiple lines.
I require the output as
No~Dt~Notes
1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh"
mean to say those new lines to be... (1 Reply)
Hi all - I''m in a little bit of jam - If you can please help
I have a file that has the following content ( please see below)
I need to read the file and then get this result in this format
------------- To put out in this format
name: sophis Total: 22328
name: tca ... (2 Replies)
I executed the following command and got Arg List too long.
find /dir1/dir2/LOG_* -prune -type f -mtime +3 -exec echo {} \;
What's that about? (2 Replies)
Hello everybody
I made code to move some files to another place for example(I moved MM file TO BIN folder ) and the MM path I put it in different file e.g(0:HOME/unixstuff/MM) so my question is who I can separate the path line and use the number 0: and MM as parameter because if I want to... (2 Replies)
I Have to check in a file that all the lines are ending at same posiotin.
Ex : line 1 is ending at position 88
line 2 should at same position i.e 88
Thanks in advance (6 Replies)
Hi All,
I got a script from one of the unix forums for reporting on filesystem usage and wanted to use it but it keeps giving me the following error.
0403-057 Syntax error at line 70
The script is shown below.
Pls help as I am new to UNIX.
# set -x
# D I S K S P A C E . S H
#
#... (2 Replies)
Hi all,
I have spent 2 hours going through the forum and have not found an answer to my question, I hope someone can help.
I have cron setup to run two commands, one at 1am and one at 3 am, the one at 1 am works but not the one at 3 am. The time is set as:
0 1 * * * /path/to/file
0 3 * * *... (3 Replies)