I have file called log.txt. file contains are like below :-
/proc
used avail
10 100
how can i extract the below strings from that file using shell script. I want the below strings to be extracted.
/proc
10
100
awk '{print $1 $4 $5}' log.txt
Using sed, and if it is spaces you have between 10 and 100:
sed -e '2d;3s/ */\n/' log.txt
if it is tabs you have between 10 and 100, and you gave GNU sed:
sed -e '2d;3s/\t\t*/\n/' log.txt
if it is tabs you have between 10 and 100, and you do not have gave GNU sed, but real tabs instead of the 2 \t above.
Avoiding sed (or awk) and using standard UNIX utilities, and if it is spaces you have between 10 and 100:
paste -s -d " " file | tr -s " " | cut -d " " -f 1,4,5 | tr " " "\n"
if it is tabs you have between 10 and 100, and you have GNU utilities:
paste -s -d "\t" file | tr -s "\t" | cut -f 1,4,5 | tr "\t" "\n"
if it is tabs you have between 10 and 100, and you do not have gave GNU utilities, but real tabs instead of the \t above and a real instead of the \n.
log.txtas well as your actual expected output rather than expecting the StackOverflow community to guess. Thanks ever-so!