나는 TEXTFILE끝에 특정 줄에 특정 문자열을 추가하십시오. -bash
personId, PERSONNAME을 포함 (particulars.txt), employmentType
particulars.txt이
1,jane,partTime
2,bob,fullTime
3,john,fullTime
나는 그것이 같은 것을 확인 할 방법 I 키의 경우 그 사람이 풀 타임 또는 파트 타임 근로자인지 여부를 확인하고 사용자에게 월급을 입력하고 그 사람에게만 파일로 다시 쓰도록 요청할 것입니다. 나는 더 자세히 설명 할 것이다. 예
Enter Name:jane
jane is a partTime staff
Enter Hourly Salary:10
위한
때문에 TEXTFILE (particulars.txt)는 이제 예 이제 두
Enter Name:bob
bob is a fullTime staff
Enter monthly Salary:1600
때문에 TEXTFILE (particulars.txt)
1,jane,partTime,10
2,bob,fullTime
3,johnfullTime
할 것이다 be
이 (210) 내가 가진 무엇 내 코드
#!/bin/bash
fileName="particulars.txt"
read -p "Enter name:" name
if grep -q $name $fileName; then
employmentType=$(grep $name $fileName | cut -d, -f4)
echo "$name is $employmentType" staff"
if [ $employmentType == "partTime" ]; then
echo "Enter hourly pay:"
read hourlyPay
#calculations for monthly salary(which I have not done)
elif [ $employmentType == "fullTime" ]; then
echo "Enter monthly salary:"
read monthlySalary
fi
else
echo "No record found"
fi
read -p "Press[Enter Key] to Contiune.." readEnterKey
나는 그 사람이 속한 않는 고용 형태 찾을에만 수 있어요,하지만 난 급여를 추가하기 위해 무엇을 할 방법/확실하지 않다 저 특별한 사람을위한 선의 끝에. 나는 sed에 대해 읽었지만 결과를 얻기 위해 sed를 사용하는 방법에 여전히 혼란스러워서 너희들에게 도움을 구한다. 사전
감사합니다. – user2211678