I am having a file "file1.txt" which is having the data as follows:
rahul 1994 Australia 40000
akash 2000 India 50000
Now i want to extract values of field 1 and field 4 in some variable.
I am doing it as follows:
while read line
do
name=$(awk '{print $1}'<< "$line")
salary=$(awk '{print $4}'<< "$line")
echo $name $salary
done < file1.txt
So i want to ask that can i assign values to name and salary by using only one awk command?
Better do this in plain bash ;
while read name _ _ salary; do
echo "$name $salary"
done < file1.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.