pls help, file name with brackets


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers pls help, file name with brackets
# 1  
Old 02-17-2012
pls help, file name with brackets

Hi all,

I have a number files like these below


Code:
R1_970804_125318
R1_970804_125404(2)
R1_980322_219282
R1_980301_210651(2)
R1_980301_210651(3)

and I'm trying to put file names into a string in order to perform some processings.

Code:
FILES=`cat namelist.txt`
for F in $FILES
do
...
...
done

For files without brackets, my script works fine. But those with brackets, it won't works.

is there a way to solve this problem?
thanks a lot!

Last edited by methyl; 02-17-2012 at 12:51 PM.. Reason: please use code tags
# 2  
Old 02-17-2012
try this way ( doublequotes )

Code:
 for F in "$FILES"

This User Gave Thanks to thegeek For This Post:
# 3  
Old 02-17-2012
That won't work either. That will make it all one giant filename instead of a list of files!

The problem isn't how you're using the for-loop, the problem is you're using backticks to shoehorn a list of files into the wrong kind of loop -- you should be using while read. It's also a useless use of cat and useless use of backticks which will do strange things to brackets spaces and the like.

What you should do to read a file line by line, is:

Code:
while read LINE # Note LINE does NOT have a $ here
do
        echo "got line $LINE"
...
done < inputfile

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 02-17-2012
You can also try this method eliminating the use of the cat command and making sure to include quotes around the $line variable.

Code:
while read line
do
    echo "$line"
    blah blah "$line"
done < namelist.txt

This User Gave Thanks to in2nix4life For This Post:
# 5  
Old 02-17-2012
thanks for your reply!

however, problem remains.
it returns error messages like: unterminated substitute in regular expression.

what i'm trying to do is update link path in these files containing the file names

Code:
while read F
do
        #to extract the line containing the path by key word CDPFCIS
        OLD_PATH=`egrep CDPFCIS $F`
        #to extract the new path by file name
        NEW_PATH=`egrep $F new_path_list.txt`
        sed -i 's@OLD_PATH@NEW_PATH@g' $F
done < namelist.txt

I guess the problem is in the egrep function, cuz the system won't allow code like this
Code:
egrep R1_970804_125404(2) namelist.txt

is there a way to solve this problem? thank you so much!
# 6  
Old 02-17-2012
grep -F will force it to consider the names as fixed strings, not regular expressions.

If your system's grep doesn't have -F, try egrep.
# 7  
Old 02-17-2012
Quote:
Originally Posted by Corona688
grep -F will force it to consider the names as fixed strings, not regular expressions.

If your system's grep doesn't have -F, try egrep.
I tried this

Code:
egrep -F R1_980302_105147(2) namelist.txt

returns: -bash: syntax error near unexpected token `('

still no luckSmilie

any ideas? thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort a text file based on names in square brackets

Hi all, I have a text file similar to this: Text More text Etc Stuff That Is Needed Etc Etc This contains over 70 entries and each entry has several lines of text below the name in square brackets. (5 Replies)
Discussion started by: Scally
5 Replies

2. Shell Programming and Scripting

Compare the value in between square brackets in file

I wanted to compare the value inside the Squre bracket after Colon ( : ) based on any value(seperated by or operator | ) inside the variable Thread and if match found then wnated to store in output file Input file : 20140320 00:08:43.918 INO 35] - Corporate hub is 20140320 00:08:43.918... (2 Replies)
Discussion started by: nes
2 Replies

3. UNIX for Dummies Questions & Answers

Pls. help with sudoers file...

Hi, I was asked to create sudoers file for operation team so they can sudo as another user and run few commands. I have updated /etc/sudoers file. User_Alias LEVEL1 = JamesF, dennisW, juanC, steveS, Cmnd_Alias SU_PROD=/bin/su prod, /bin/su - prod Cmnd_Alias SU_NYOP=/bin/su... (2 Replies)
Discussion started by: samnyc
2 Replies

4. Shell Programming and Scripting

parsing characters and number from a big file with brackets

I have a big file with many brackets () in it from which I need to parse number characters and numbers. Below is an example of my file 14 (((A__0:0.02,B__1:0.3)0:0.04,C__0:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362; 15... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

5. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

use awk to edit a file..pls help

hey i want to over write the fourth field of a ':' delimited file by first finding the required row by using grep. i have done the following cat file | grep no. | awk -F ':' { $4=count; print $1:$2:$3:$4;} the correct values are being printed but nothin is bein added to the file..please... (5 Replies)
Discussion started by: dhe.arora
5 Replies

7. Shell Programming and Scripting

How to echo Brackets from a file

I'm a beginner of c shell scripting. How I can echo a whole line from a file with bracket in it? Ex. Inside the file.txt abcd efghi This is what inside the c shell set IN_FILE = file.txt set GREP_KEY = 'abcd' set IN_LINE = `grep ${GREP_KEY} ${IN_FILE}` echo $IN_LINE After... (7 Replies)
Discussion started by: zeahr
7 Replies

8. UNIX for Dummies Questions & Answers

pls. help with appening a file

Hi, I wrote a script, but it's not working. Please advise. I want to add the text at the end of the file. Should I use sed or awk. Not sure any thing is fine with me. #!/usr/bin/ksh DATE=`/usr/bin/date '+%m%d%y'` cp -p /etc/inittab /etc/inittab_$DATE... (5 Replies)
Discussion started by: samnyc
5 Replies

9. Shell Programming and Scripting

compare 2 file and print difference in the third file URG PLS

Hi I have two files in unix. I need to compare two files and print the differed lines in other file Eg file1 1111 2222 3333 file2 1111 2222 3333 4444 5555 newfile 4444 5555 Thanks In advance (3 Replies)
Discussion started by: evvander
3 Replies

10. Programming

File I/O ERRORS.. PLS HELP..

Hi people, I am having a little problem with my client side of the concurrent programming, i have a makefile, serverside and clientside directories. makefile works well with serverside files. and now when i added the clientside files to the makefile and compiled... it gives me the follwong error.... (0 Replies)
Discussion started by: SwetaShah
0 Replies
Login or Register to Ask a Question