How to read nth word from delimited text file?

Hi i am new in scripting
how i can get 2 elements from first line of delimited txt file in shell scripts.

AA~101010~0~AB~8000~ABC0~
BB~101011~0~BC~8000~ABC~
CC~101012~0~CD~8000~ABC0~
DD~101013~0~AB~8000~ABC~
AA~101014~0~BC~8000~ABC0~
CC~101015~0~CD~8000~ABC~

can anyone plse help?

Thanks in advance!!!!

awk -F'~' 'NR==1{print $2,$4}' input.txt
1 Like

try

cat input.txt | cut -d "~" -f2,4
1 Like

use exit, so that other lines will not be read by awk

awk -F'~' 'NR==1{print $2,$4;exit}' input.txt
1 Like