0

The content of the file is fixed.

Example:

2016-03-28T00:02 AAA 2016-03-28T00:03  ADASDASD
2016-03-28T00:03 BBB 2016-03-28T00:04  FAFAFDAS
2016-03-28T00:05 CCC 2016-03-28T00:06  SDAFAFAS
....

Which command can I use to get all sub-strings, AAA, BBB, CCC, etc.

Biffen
  • 6,249
  • 6
  • 28
  • 36
RhysJ
  • 153
  • 1
  • 3
  • 19

3 Answers3

2

you can use cut and awk and perl for this.

cat >> file.data << EOF
2016-03-28T00:02 AAA 2016-03-28T00:03  ADASDASD
2016-03-28T00:03 BBB 2016-03-28T00:04  FAFAFDAS
2016-03-28T00:05 CCC 2016-03-28T00:06  SDAFAFAS
EOF

AWK

awk '{ print $2 }' file.data
AAA
BBB
CCC

CUT

cut -d " " -f2 file.data
AAA
BBB
CCC

PERL

perl -alne 'print $F[1] ' file.data 
AAA
BBB
CCC
OmPS
  • 331
  • 3
  • 12
0

You can use AWK for this:

jayforsythe$ cat > file
2016-03-28T00:02 AAA 2016-03-28T00:03 ADASDASD
2016-03-28T00:03 BBB 2016-03-28T00:04 FAFAFDAS
2016-03-28T00:05 CCC 2016-03-28T00:06 SDAFAFAS
jayforsythe$ awk '{ print $2 }' file
AAA
BBB
CCC

To save the result to another file, simply add the redirection operator:

jayforsythe$ awk '{ print $2 }' file > file2
birdoftheday
  • 816
  • 7
  • 13
0

You can use cut:

cut -d' ' -f 2 file
birdoftheday
  • 816
  • 7
  • 13
demosito
  • 223
  • 1
  • 7