Hi all,
I want the 2nd column of every file in the directory in a single file with the file name as column header.
$cat file1.txt
a b c
d e f
$cat file2.txt
f g h
g h j
$cat file3.txt
a b d
f g h
Expected output (with column header)
$cat out.txt
file1.txt file2.txt file3.txt
b g b
e h g
Thanks Much
You can try this ...
ls directory-name | while read line
do
touch output.txt
echo $line > temp.txt
cut -d' ' -f2 $line >> temp.txt
paste temp.txt output.txt > output2.txt
cp output2.txt output.txt
rm output2.txt
rm temp.txt
done
1 Like
Hi,
This code outputs the file names but not their 2nd column. My files are tab-delimited
Thanks
---------- Post updated at 07:07 PM ---------- Previous update was at 06:44 PM ----------
The actual value of tab (control v TAB) on the bash works here !! thanks !