Cutting specific name from configuration file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting specific name from configuration file
# 1  
Old 02-28-2005
Cutting specific name from configuration file

Hi falks,

I have the following configuration file structure:

file1:N
file2:Y
file3:Y
file4:N
......

I need to cut from the configuration file only the file with the sign "Y" in the end and copy it to some directory.

What is the best way to do it?

Thanks in advance,
Nir
# 2  
Old 02-28-2005
Code:
#!/bin/ksh

configFile='file.cfg'

while IFS=: read fileName yn
do
   [ "${yn}" = "Y" ] && cp "${fileName}" newDirectory
done < "${configFile}"


Last edited by vgersh99; 02-28-2005 at 05:18 PM..
# 3  
Old 02-28-2005
Hey vgersh99,

Thanks a lot!
It's a very elegant solution!

best regards,
Nir
# 4  
Old 03-01-2005
You got a solution. Anyway my try as,

awk '/:Y$/ { split($0,a,":"); print "cp "a[1]" ." }' <filename> | sh

It will work too.

HTH.
# 5  
Old 03-01-2005
Hey muthukumar,

Thanks a lot for your solution.
I've checked it and it works ,but under specific circumstances:
The file in the configuration file must contain a full path.
My configuration file looks as the following:

RiGHTv/Java/lib/dispatcher.war:Y
CoreAPP/Java/deploy/RiGHTvCore.war:Y
XBIPApplication/Java/deploy/XBIPApplication.war:N
RiGHTv/Java/lib/Ris.war:N
SUIFW/Java/deploy/SUIFW.war:N
AMS/Java/deploy/Ams.ear:N
....

The file does not contain its root directory. The root directory is entered during the running, as an input from the user.The root directory is a build area of jar,war,ear,tar and sql files, which belongs to a specific build version.
Therefore,the solution of vgersh99 is more suitable for me because i concatenate the root directory to the file name from the conf file.
I wrote the following function:

copy_files_from_build_area()
{
configFile='copybuild.conf'

while IFS=: read fileName yn
do
[ "${yn}" = "Y" ] && check_if_file_exist && cp "${BUILD_DIR}/${fileName}" ${PRODUCTS_DIR}
done < "${configFile}"
}

Anyway,thanks a lot!

Best regards,
Nir
# 6  
Old 03-01-2005
Yes. It is correct. We can try more derived ways as like,

awk '/Y$/ { split($0,a,":"); print a[1] }' testfile | while read file
do
cp ${BUILD_DIR}/${file}" ${PRODUCTS_DIR}
done

keep posting.
# 7  
Old 03-01-2005
Now it works perfect!
Beautiful solution !

Best regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cutting specific columns from lines

I am trying to remove columns 81-97 from a line that can be as long as 114 characters. Because a number of lines might not have under 80 characters, using the cut command following by paste could be a problem. While sed might work, is there some other utility that could do this more easily? ... (9 Replies)
Discussion started by: wbport
9 Replies

2. Shell Programming and Scripting

Cutting pattern from source file

hi gurus, I want to cut a selected pattern from the source file For example <operation > Update Update Update <operation> I want to select the three lines having update and the one above <operation> to be cut from source file and paste it to another As of now i... (2 Replies)
Discussion started by: r_t_1601
2 Replies

3. Shell Programming and Scripting

Cutting rows at specific length

Hi, i have a file containing nrows and 3cols. i want to cut it in specific length and save output to individual files. 1 2 3 4 5 6 5 8 9 10 11 12 13 14 15 16 17 18 i need to cut the file say every 2 rows and save it in individual file. 01.dat contains 1 2 3 4 5 6 02.dat 7 8 9... (10 Replies)
Discussion started by: ida1215
10 Replies

4. Shell Programming and Scripting

Cutting file name from end

Dear Friends, I want to take last 10 characters of a file name in a variable. E.g. file name is 123432311234567890.txt then we want "1234567890" to be taken in an variable. Request you to guide me to do the same Thanks in anticipation Anushree (7 Replies)
Discussion started by: anushree.a
7 Replies

5. Shell Programming and Scripting

Cutting out text from specific portion on filename

Hi, how do I go about cutting out the first numeric characters after the word "access"? access1005101228.merged-00.15.17.86.d8.b8.log.gz (16 Replies)
Discussion started by: GermanJulian
16 Replies

6. Shell Programming and Scripting

Cutting specific line of a file by checking condition

testfile.csv 0","1125209",,"689202CBx18888",,"49",,,"NONMC",,,,,"01112010",,,,,,,"MTM- "1","",,"689202ABx19005",,"49",,,"NONMC",,,,,"01072010",,,,,,,"MTM- testfile.csv looks like above format if the second column is null then get 23rd column and store in a different varible .. add all the... (1 Reply)
Discussion started by: mgant
1 Replies

7. Shell Programming and Scripting

Cutting specific lines from a file

Hi, I have a file named Mani.txt. The contents are like this cat Mani.txt -------------------------------------------------------- Hi there how r u My Name is Mani Bye ------------------------------------------------------------ I want to cut the first and last lines from the file... (15 Replies)
Discussion started by: pathanjalireddy
15 Replies

8. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

9. Shell Programming and Scripting

Cutting last few characters of file name

Dear Friends, Here I have two queries. 1. Want to make folder named as last three characters of a file name (length of file name can vary file to file) E.g File name is AAAACCCCBBBB.txt (12 Characters excluding file extension) then folder to be created is BBB Irrespective of... (7 Replies)
Discussion started by: anushree.a
7 Replies

10. Shell Programming and Scripting

Cutting a tab delimiter file

I have a 30 column tab delimited record file. I need to extract the first 10column. The following command to cut was not working cut -f 1-10 -d "\t" filename. Could any one keep on this . Thanks in Advance (4 Replies)
Discussion started by: vinod.thayil
4 Replies
Login or Register to Ask a Question