Fred_Scuttle
Fred_Scuttle

Reputation: 37

Linux substring (cut) output in shell script

In Linux (Raspbian distro) I'm trying to extract the date part of a file name which works when I type it in directly into the terminal (see below).

$ file1="access_point20140821.csv"
$ echo $file1 | cut -c13-20
$ 20140821

However, when I put this into a shell script I can't seem to extract the date part of the file name. The echo line just returns "Date Part" with nothing following it. I suspect this is something to do with how I am assigning the variable DATE_PART. Can anyone help?

FILENAME="access_point20140821.csv"
DATE_PART=$FILENAME | cut -c13-20
echo "Date Part $DATE_PART"

Upvotes: 0

Views: 2303

Answers (1)

enrico.bacis
enrico.bacis

Reputation: 31494

You are not echoing the file, you are trying to execute it, you should do:

FILENAME="access_point20140821.csv"
DATE_PART=$(echo $FILENAME | cut -c13-20)
echo "Date Part $DATE_PART"

Upvotes: 1

Related Questions