I have a text file like this:
aaaa bbbb cccc
dddd eeee ffff
gggg hhhh iiii
...
..
.
How can I create a text file only with first column of every lines with awk
or sed
like this?
aaaa
dddd
gggg
...
..
.
I have seen similar topics but I could not resolve my problem!
If your input is
aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii
and what you want is:
aaaa dddd gggg
then you can use any of:
awk NF=1 input.file sed 's/ .*//' input.file cut -d' ' -f1 input.file
Using awk
: By setting number of fields to 1:
awk '{NF=1}1' inputfile
Using grep
and look arounds:
grep -oP '^.[^ ]+' inputfile
Using sed
backrefrencing:
sed -r 's/(^.[^ ]+).*/\1/' inputfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With