i have the following files with content
file a content;
1234|wert|
file b content;
2345|byte|
file c content;
9999|kilo|
i want to read the contents of three files seperately and for each of them select the first column and output below
welcome 1234
welcome 2345
welcome 9999
anbu23
2
$ cat file
1234|wert|
$ cat file | IFS="|" read a b
$ echo "welcome $a"
welcome 1234
how can i use this script to read about 100 or more txt file and output the same message
anbu23
4
cd /dir1/dir2
for i in *
do
cat $i | IFS="|" read a b
echo "welcome $a"
done
sed 's/\([^|]*\).*/welcome \1/' files
AWK version
awk -F\| 'FNR==1{print "Welcome "$2}' *.txt
That should be $1, not $2.
Regards,
Alister