Hi all,
I need to convert this file having just one column into two column file
current file:
a
15
b
21
c
34
d
48
e
10
wanted:
a 15
b 21
c 34
d 48
e 10
Thanks in advance
Hi all,
I need to convert this file having just one column into two column file
current file:
a
15
b
21
c
34
d
48
e
10
wanted:
a 15
b 21
c 34
d 48
e 10
Thanks in advance
Try:
awk '{getline s; print $0, s}' file
Its only giving me the 2nd column..
my actual file is like
/home/xyz/file1.txt
10:30 20090407
/home/xyz/file2.txt
11:30 20090407
/home/xyz/file3.txt
10:40 20090407
/home/xyz/file4.txt
09:30 20090407
It should giving like
file1.txt 11:30
file2.txt 11:30 .........
try this for your specific requirements
#!/bin/sh
sed -n '1~2p' file_name >>temp
sed -n '0~2p' file_name >>temp_3
for line in `cat temp`
do
basename `echo $line`>>temp_2
done
paste temp_2 temp_3 |awk '{print $1 " " $2}'
rm -f temp_2 temp_3 temp
awk '{sub(".*/","");s=$0; getline; print s, $1}' file
or,
awk -F "/" '{getline n;split(n,a," ");print $NF,a[1]}' file
file1.txt 10:30
file2.txt 11:30
file3.txt 10:40
file4.txt 09:30
working for me.
$ awk -F "/" '{getline n;split(n,a," "); print $NF,a[1]}' new
awk: syntax error near line 1
awk: bailing out near line 1
$ cat new
/home/xyz/file1.txt
10:30
which OS?
use nawk,gawk or /usr/xpg4/bin/awk on solaris
---------- Post updated at 01:48 PM ---------- Previous update was at 01:43 PM ----------
also, if you are having only one field in you next line then no need to use split.
awk -F "/" '{getline n;print $NF,n}' file
/usr/xpg4/bin/awk on solaris
while read A && read B
do
echo "$A $B"
done < infile
Thanks frans your reply works:b:
Redundant answer as the OP deleted his (2nd) question....
tyler_durden
Sorry tyler I did it myself, I am improving
Thanks though!!
This should also work.
sed 'N; s/\n/ /' file
Or may be this is what you are looking for:
sed 'N; s~.*/~~; s/\n/ /' file
Or may be this:
sed 'N; s~.*/~~; s~ [^ ]*~~; s/\n/ /' file
Hi.
paste - - < file
regrettably, this usage is not easily discerned from either man paste or info coreutils paste.
Best wishes ... cheers, drl
Using awk I'll opt for:
awk -F'[\/ ]' '{printf ((NR%2)?$NF OFS:$1RS)}' file