Vi editor in UNIX hwk HELP!!

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Vi editor in UNIX hwk HELP!!
# 1  
Old 05-01-2013
Vi editor in UNIX hwk HELP!!

i need help with this homework. PLEASE

Assignment:
Create a directory "preFinal" in your home directory. Create empty files "a", "b", "c", etc in directory preFinal in the amount that match the number of directories preFinal*

This the code i have within Vi editor. But it is not working all the way. After runing bash about 10 times the letters jump from i to a random number and not in abc order. PLEASE TELL me how to do this.
Code:
#!/bin/bash

dir="preFinal"

if [ -d $dir ]; then
       echo "dir exists, moving..."
       i=0
       for dir_bkp in `ls -lrt | grep "^d" | egrep "preFinal*" | awk '{print $NF}' | sort -nr`; do
               next=$(echo "$dir_bkp" | sed 's/^.*\.//')
               if [ $next == "preFinal" ]; then
                       next=-1
               fi
               next=`echo $next|sed 's/^0*//'`
               ((next++))
               next=$(printf "%03d" $next)
               #next="00$next"
               echo $next
               mv $dir_bkp $dir.$next
               ((i++))

else
       mkdir $dir
       touch $dir/a
fi

Bre/ GSW university / Unix CIS 3200 / Simon

Last edited by bcute92; 05-01-2013 at 09:51 PM..
# 2  
Old 05-01-2013
Please fill out the homework template, the course information you've given is incomplete.
# 3  
Old 05-01-2013
Quote:
Originally Posted by Corona688
Please fill out the homework template, the course information you've given is incomplete.
I fixed it.
# 4  
Old 05-01-2013
Quote:
Originally Posted by bcute92
i need help with this homework. PLEASE

Assignment:
1. Create a directory "preFinal" in your home directory. In case that such directory exist, rename the existing one into "preFinal.000" and then create empty directory preFinal. While renaming existing preFinal into preFinal.000 you may discover that preFinal.000 also exists, so it needs to be renamed into preFinal.001 and so on.
2. Create empty files "a", "b", "c", etc in directory preFinal in the amount that match the number of directories preFinal*

This the code i have within Vi editor. But it is not working all the way. After runing bash about 10 times the letters jump from i to a random number and not in abc order. PLEASE TELL me how to do this.

... ... ...

Bre/ GSW university / Unix CIS 3200 / Simon
You might want to review the statement in item #2 above. It isn't clear to me that you're adding files to the correct directory.

Are the names of the files really random after the 1st 9, or is there just a jump with some names you expected skipped? Do you think there might be any relationship between the fact that values 61 through 69 worked as expected and the next one failed when you're using "\xdigits" as a format string to printf to create your file names?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

What is Your Favorite Editor for Linux and UNIX? | A Video in 1080 HD

We have asked UNIX.com users over the years what is their favorite editor and why. Here is the top three answers. Here is a new YT video on this question: What Editor Does Everyone Use? https://youtu.be/gqE8RTZZt9g Of course, vi was the overwhelming favorite. Credits: 1080 HD... (3 Replies)
Discussion started by: Neo
3 Replies

2. UNIX for Dummies Questions & Answers

Vi editor will not open new to UNIX. help please.

vi: syntax error at line 1: `)' unexpected when I try to vi into the /etc/vfstab, the return gives me the above error. how can resolve this so that I can have access into vi. (6 Replies)
Discussion started by: dovestar
6 Replies

3. HP-UX

UNIX VI editor equivalent of LINUX

Hi All, I am comfortable working in LINUX and need equivalents for HP-UX for below mentioned, 1. We use TAB key to expand/reveal a name in LINUX. Is there any way to make this work for UNIX, where it is double escape. 2. Also can we use make use of left,down,up,right keys instead... (3 Replies)
Discussion started by: pradebban
3 Replies

4. Shell Programming and Scripting

Copy from vi Editor ( unix ) to windows

How to copy the complete content from a file in vi Editor to windows ( notepad ). I can use " select " and paste it to windows but this is restricted to current page. Not allowing me to scroll down or up when selecting the content.:confused: (1 Reply)
Discussion started by: frintocf
1 Replies

5. UNIX for Dummies Questions & Answers

Any better text editor for unix?

Do you know any text editor (other than Gvim, which I am using) which is made specially for c type languages? The reason I ask for it is: I just spent 3 hours trying to find out start "if" and its end "if end".:wall: I hope there is an editor which can link each if with its closing endif . (4 Replies)
Discussion started by: animesharma
4 Replies

6. Shell Programming and Scripting

VI Editor - question for unix gurus !!

I have created a dummy file -demo.txt On my machine-A (oslevel-5300-08) I can display the file content in HEX format through VI editor using :%!xxd but on other machine-B (oslevel - 5300-06) , I get error as "sh: xxd: not found." machine-A: $ cat demo.txt Hello World ! I can display... (7 Replies)
Discussion started by: Rahulpict
7 Replies

7. Shell Programming and Scripting

set EDITOR=vi -> default editor not setting for cron tab

Hi All, I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by set EDITOR=vi it does not open a vi editor , rather it do as below..... ///////////////////////////////////////////////////// $ set... (6 Replies)
Discussion started by: aarora_98
6 Replies

8. Shell Programming and Scripting

Using Unix screen cmd effecting Vi editor

Hello, I enjoy using the unix screen utility, but my vi sessions lose the ability to syntax highlight code and split screen(:vs or :sp). When not using screen, I can do those things within vi. Anybody experience this and know the fix? Thanks (1 Reply)
Discussion started by: geephei
1 Replies

9. Shell Programming and Scripting

how to make VI editor show colors in Unix

Hi, I saw some people's vi editor show different colors on the text according the nature of text when using it. It would be nice if I can see diffrerent colors with my vi editor. Do anybody know how to set it up? I use PowerTermPro program to access unix machine. I tried to use vim editor but... (7 Replies)
Discussion started by: whatisthis
7 Replies

10. UNIX for Advanced & Expert Users

Unix vi editor

Dear All, Is there a way to handle special french, spanish character is vi editor (Sun Solaris 8). Foll. is a label in notepad (windows), Cliquez ici pour revenir Ã_ la recherche de l'hôtel this label is stored in a text file, when i tranfer this file to unix using ftp (tried both ansi & bin... (6 Replies)
Discussion started by: lloydnwo
6 Replies
Login or Register to Ask a Question