Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut question 1

Status
Not open for further replies.

moreCA

Programmer
Feb 11, 2003
68
US
I have a file name that I need to cut the first 3 letters of it an put into a variable so I can compare it back to that filename and then do some manipulation from there. I am having issues with the cut command for that.

For example:

fname=paycheck42.txt
I need newname to be pay

Then I want to compare newname to fname and if fname contains pay then the file will go to one directory and if it does not contain pay then it will go to a different directory
 
Hi:

I'll leave the file copy to you:

#!/bin/ksh

fname=paycheck42.txt

var=$(echo "$fname"|cut -c1-3)

# only 1 of the four doesn't contain pay string
for i in 1pay2.file xxx.file pay.file myfile.pay
do

if [[ $i = *"$var"* ]]
then
echo "file $i contains 'pay'"
else
echo "file $i DOES NOT contain 'pay'"
fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top