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
  • 5,791
  • 5
  • 29
  • 34
RhysJ
  • 143
  • 2
  • 15

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
  • 291
  • 3
  • 10
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
  • 806
  • 7
  • 13
0

You can use cut:

cut -d' ' -f 2 file
birdoftheday
  • 806
  • 7
  • 13
demosito
  • 213
  • 1
  • 6