Very New To Unix Shell Programming:Plz Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Very New To Unix Shell Programming:Plz Help
# 1  
Old 09-10-2008
Very New To Unix Shell Programming:Plz Help

Hi Gurus

I am very new to Unix Shell Prog. I have a file in format

Q1 Dirname-FileName Score Remarks

i.e. containing columns separated by space. I want to read Column 1 and 2 and then join them to make a string that would be a path to a file. I will use this string to fetch the files and copy in a directory..

If someone can help plz. I have no idea what commands to use??
thanks in adv
# 2  
Old 09-10-2008
try out this

Hi,

try out the below script:

Assumtion:
If your file is /home/test.txt and contents of the file are:

/home/test test1
/home/test test2

like

dirname filename

The below script shud work.. let me know if you have any questions

#!/bin/ksh
no_of_lines=`cat /home/test.txt|wc -l`
no_of_lines=`echo $no_of_lines | sed 's/" "/''/g'`
while [ $no_of_lines -gt 0 ]
do
dirname=`head -$no_of_lines /home/test.txt | tail -1 | cut -f1 -d' '`
filename=`head -$no_of_lines /home/test.txt | tail -1 | cut -f2 -d' '`
slash=/
path=$dirname$slash$filename
cp $path /home/test_dir
no_of_lines=`expr $no_of_lines - 1`
continue
done
exit 0
# 3  
Old 09-10-2008
Huh? That's a really convoluted way of saying

Code:
while read dir file rest; do
  echo "$dir/$file"
done </home/test.txt

# 4  
Old 09-10-2008
hi era,
that was a very good solution...
can u tell me if that works if the file is comma delimited.. or any other delimiter is used other than space.
can u tell me how to do if it is comma delimited?

Thanks,
# 5  
Old 09-10-2008
Search for IFS
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Plz help me out use OFMT operator in awk programming

Hi While calculating the sum of 6 and 7 fileds it is calculate the wrong value because of floating point like 7898778.10 awk ' BEGIN { FS = OFS = "|" } NR == 1 { next } { UX = $1 OFS $3 OFS $4 OFS $5 p1 +=$6 p2 +=$7 } END { for(i in UX) ... (8 Replies)
Discussion started by: jagu
8 Replies

2. Homework & Coursework Questions

Help for programming a UNIX Shell in C++

1. The problem statement, all variables and given/known data: Hello! :) I currently got the task of programming a UNIX Shell for practice. The functionality is as follows: 1. Entering commands with the keyboard. Enter stops the input and creates a process which should start any program 2.... (0 Replies)
Discussion started by: DarkDan
0 Replies

3. Shell Programming and Scripting

Help for programming a UNIX Shell in C++

Hello! :) I currently got the task of programming a UNIX Shell for practice. The functionality is as follows: 1. Entering commands with the keyboard. Enter stops the input and creates a process which should start any program 2. the shell waits for termination of each command before... (1 Reply)
Discussion started by: DarkDan
1 Replies

4. Shell Programming and Scripting

UNIX shell programming

Hi guys i have two different line input M5.7&a : M5 minimum density is 20%, maximum density is 80%, DENSITY PERM=M5.8&a(180) ......... 6 violations found. M6.7&a : M6 minimum density is 20%, maximum density is 80%, DENSITY A=M6.8&a(180) ......... 6 violations found. need... (2 Replies)
Discussion started by: ashokkrishna063
2 Replies

5. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

6. Homework & Coursework Questions

Plz Help Me in This question in Shell Programming

2- Write a bash shell script filestatic. The script should examine the number files in directories given as arguments (parameters) to this script. a. if one argument is given, the script should count and report the number of files in this directory. Only regular files should be counted, not... (1 Reply)
Discussion started by: tahseen_22334
1 Replies

7. Shell Programming and Scripting

Plz Help Me in This question in Shell Programming

2- Write a bash shell script filestatic. The script should examine the number files in directories given as arguments (parameters) to this script. a. if one argument is given, the script should count and report the number of files in this directory. Only regular files should be counted, not... (1 Reply)
Discussion started by: tahseen_22334
1 Replies

8. Shell Programming and Scripting

UNIX Shell Scripting / Programming

Hi, I am looking for a PDF or an e-book which can show in details how to do Shell Scripting or Programming. Can anybody provide me with a link to such a tutorial? I have downloaded some tutorials but they show only basics and not give any in-depth study material. I am using Red Hat Linux... (2 Replies)
Discussion started by: indiansoil
2 Replies

9. Shell Programming and Scripting

Shell Programming in unix

Hi, i want to read a full file. If i want to split the file and by reading parralel each, i can save the time. Can any body give me the suggesion?? ia m using this function to read a file and using that i have to grep in another file. since the file 1 is huge it is taking lot of time. ... (3 Replies)
Discussion started by: nivas
3 Replies

10. Shell Programming and Scripting

shell programming in unix

Hi, Iam using split command to split the files. Splitted files will be named as xaa xab xac xad etc. Directories will be test1,test2,test3..... Now i want to select the splitted files one by one and have to place in test directories. can anybody give the soulution??? (2 Replies)
Discussion started by: nivas
2 Replies
Login or Register to Ask a Question