LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-02-2005, 02:57 AM   #1
yaadhav
LQ Newbie
 
Registered: Aug 2005
Location: I live in a world full of anger and hate
Posts: 3

Rep: Reputation: 0
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!!
 
Old 08-02-2005, 03:08 AM   #2
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
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
 
Old 08-02-2005, 09:56 PM   #3
shengchieh
Member
 
Registered: Jul 2004
Location: Palo Alto, CA
Distribution: #! Korora
Posts: 472

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

Sheng-Chieh
 
Old 08-20-2005, 02:17 PM   #4
kennedy01
LQ Newbie
 
Registered: Nov 2003
Location: Georgia
Distribution: Slackware 10.1
Posts: 28

Rep: Reputation: 15
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.
 
Old 08-20-2005, 03:05 PM   #5
kennedy01
LQ Newbie
 
Registered: Nov 2003
Location: Georgia
Distribution: Slackware 10.1
Posts: 28

Rep: Reputation: 15
got it..
Code:
CURDIR=$(pwd | sed 's/\//\\\//g')
ls -R ./ *.mp3 | grep "./" | sed "s/:$//g" | sed 's/^.\//'$CURDIR'\//g'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Linux Shell Scripting Help RowanB Programming 13 11-12-2004 04:07 PM
Linux Shell Scripting using BASH Help! fooforon Programming 5 02-05-2004 09:16 AM
Two Linux shell scripting questions thepryme Programming 5 10-23-2003 07:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration