LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux Shell Scripting (https://www.linuxquestions.org/questions/linux-newbie-8/linux-shell-scripting-349120/)

yaadhav 08-02-2005 02:57 AM

Linux Shell Scripting
 
I want to write a short shell script to read a date from the keyboard using the read command. The date should be of the form “10/12/03”. The first number should be placed in a variable “month”, the second into a variable “day”, the third into the variable “year”. I alos want to print each variable on a separate line. Assume all dates are in this format: mm/dd/yy.

Would it be easy or difficult to modify my script to accept input of the form mm-dd-yy?

Can someone please tell me how to do it!!

phil.d.g 08-02-2005 03:08 AM

Re: Linux Shell Scripting
 
Quote:

Originally posted by yaadhav
I want to write a short shell script to read a date from the keyboard using the read command. The date should be of the form “10/12/03”. The first number should be placed in a variable “month”, the second into a variable “day”, the third into the variable “year”. I alos want to print each variable on a separate line. Assume all dates are in this format: mm/dd/yy.
Thats nice!
Quote:

Originally posted by yaadhav
Would it be easy or difficult to modify my script to accept input of the form mm-dd-yy?
Easy
Quote:

Originally posted by yaadhav
Can someone please tell me how to do it!!
Sounds like a homework question to me, google for bash tutorials and have a look at sed and awk

shengchieh 08-02-2005 09:56 PM

http://www.dreamsyssoft.com/shell_prog.jsp (UNIX Shell Scripting Tutorial)

Sheng-Chieh

kennedy01 08-20-2005 02:17 PM

sed variables revisted
 
same question pretty much. im working on a script to rename files. I found a mp3 rename script as follows

Code:

if [ "$1" ]
then
  if [ -d "$1" ]
  then
    cd "$1"
  else
    echo invalid directory
    exit
  fi
fi

for i in *
do
  OLDNAME="$i"
  NEWNAME=`echo "$i" | tr ' ' '_' | tr A-Z a-z | sed s/_-_/-/g`
  if [ "$NEWNAME" != "$OLDNAME" ]
  then
    TMPNAME="$i"_TMP
    echo ""
    mv -v "$OLDNAME" "$TMPNAME"
    mv -v "$TMPNAME" "$NEWNAME"
  fi
done

Im wanting to ls a working folder and feed the directories that reside in the working area into the rename tool.

Here's what I have so far, the last sed statement keeps putting "$CURDIR" instead of the value of pwd.

Code:

CURDIR=$(pwd)
ls -R ./ *.mp3 | grep "./" | sed "s/:$//g" | sed s/^.\//$CURDIR/g

#For testing, will be removed once working
echo $CURDIR

The problem is in the last sed statement.

Thanks guys. Oh, and this is not homework...for fun as Linux should be! Once working I'll share the working vesion with a "for" loop.

kennedy01 08-20-2005 03:05 PM

got it..
Code:

CURDIR=$(pwd | sed 's/\//\\\//g')
ls -R ./ *.mp3 | grep "./" | sed "s/:$//g" | sed 's/^.\//'$CURDIR'\//g'



All times are GMT -5. The time now is 04:11 PM.