i have a file as:
1
2
3
4
5
i want output as :
1 2 3 4 5
can anybody help on this??
i have a file as:
1
2
3
4
5
i want output as :
1 2 3 4 5
can anybody help on this??
Try this:
cat filename | xargs
Some thing similar
+++++++
cat filename | paste -s -
+++++++
Or for more advance operations, I have awk script by some forum like this
+++++++
#! /bin/sh
## ------------------------------------------------------------
## -- Transpose a matrix:
## -- Assumes all lines have same number of fields
## --
## -- Usage:
## -- script <STDIN> ^D
## -- script <input file>
## -- cat <input file> | script
## ------------------------------------------------------------
exec awk '
BEGIN {
FS = ","
OFS = ","
}
NR == 1 {
n = NF
for (i = 1; i <= NF; i++)
row [i]= $i
next
}
{
if (NF > n)
n = NF
for (i = 1; i <= NF; i++)
row [i]= row [i]"," $i
}
END {
for (i = 1; i <= n; i++)
print row
[i]}' ${1+"$@"}
+++++++
This assumes "," as input file field seperator
Why are you using cat?
xargs < filename
thnx a lot for ur nice suggestions ;)......
Or:
echo $(<filename)
$ printf "%s\n" 1 2 3 4 5 > filename
$ echo $(<filename)
$ echo $(cat < filename)
1 2 3 4 5
$
When posting non-standard solutions, please specify which shell you are using.
Point taken. It works in ksh and the so-called POSIX sh shell.
Well if transposing is what you want...why not use the transpose command?
The example I gave was in a standard POSIX shell; there it doesn't work.
If it works with /bin/sh, then /bin/sh is probably bash or ksh93.
I was confused by this when I started to administrate HP-UX systems relatively recently. Their /bin/sh is distinct from the Bourne POSIX standard shell, it is apparently known as "the POSIX shell" and has a lot of ksh features (but not all). From the HP-UX 11.23 man page:
What operating system were you testing on? The effect you see is what I'd have expected on Solaris, for example, where they seem to have a policy of retaining every piece of prehistoric paraphernalia they can (/usr/bin/awk is the one I find particularly frustrating).
A lot of features in ksh are not part of the POSIX shell specification. This is one of them.
That is irrelevant. I was testing with a standard POSIX shell; I could have had the same result on many systems.
$(<filename) is not part of the POSIX specification; it is an extension implemented by some POSIX shells, primarily bash and ksh93.
So it's safe to say that the /bin/sh that HP choose to call the POSIX shell is in fact a superset of POSIX, much like bash and ksh93.
I couldn't find the POSIX specification itself... unless SuSv3 is the same thing? I seem to find the terms used almost interchangeably. Anyway, as you say, SuSv3 says nothing about $(< ), nor does it mention brace expansion (test{1,2,3} becomes test1 test2 test3), which the shell in question also seems to support.
The Open Group -- the Single UNIX Specification Version 3
We digress.
It probably is one of those two.
What does /bin/sh --version return?
Yes.
Then it must be bash (or a more recent version of ksh93 than I have).
No luck with that:
$ sh --version
--version: A specified flag is not valid for this command.
However using the ksh method (i.e. Ctrl-V while in set -o vi command mode):
$ Version M-11/16/88f
It does appear to behave more Korny than Bashy. The above is from a HP-UX 11iV2 (11.23) system.
By contrast:
$ ksh
$ Version 11/16/88
$ bash --version
GNU bash, version 3.00.14(1)-release (hppa2.0w-hp-hpux11.11)
Copyright (C) 2004 Free Software Foundation, Inc.