Hi
I use the following code to replace �.' with �N' in my files and keep both versions.
awk '{ gsub(/\./,"N"); print }' file_0001.txt > path/to/new/dir/file_0001.txt
I need help on how to apply the code to 100 files instead of doing them one file at a time. The files are labeled file_0001.txt to file_0100.txt.
Thanks
joseph
Assuming the only files in the current directory with a filename pattern of file_0*.txt are the ones you wish to make editted copies of then the following would do the trick:
for FILE in file_0*.txt; do
awk '{ gsub(/\./,"N"); print }' ${FILE} > path/to/new/dir/${FILE}
done
Hi
Thank you for your help. I got an error.
here is the code:
#!/bin/bash
#
for FILE in s_7_1_0*_qseq.txt; do
awk '{ gsub(/\./,"N"); print }' ${FILE} > /Users/mydir/${FILE}
done
I named it 'script.sh'
and this is what I did:
chmod +x script.sh
./script.sh
this what I got:
'/script.sh: line 3: syntax error near unexpected token `do
done' '{ gsub(/\./,"N"); print }' ${FILE} > /Users/mydir/${FILE}
The same script is working fine for me.
Open the file in "vi" and check there may some characters like "^M" in the file .
just a ls and reading using a while should do
ls file* | while read file
do
# apply changes, transformations
done
jdhahbi:
Hi
Thank you for your help. I got an error.
here is the code:
#!/bin/bash
#
for FILE in s_7_1_0*_qseq.txt; do
awk '{ gsub(/\./,"N"); print }' ${FILE} > /Users/mydir/${FILE}
done
I named it 'script.sh'
and this is what I did:
chmod +x script.sh
./script.sh
this what I got:
'/script.sh: line 3: syntax error near unexpected token `do
done' '{ gsub(/\./,"N"); print }' ${FILE} > /Users/mydir/${FILE}
Works for me:
$ cat ./script.sh
#!/bin/bash
#
for FILE in s_7_1_0*_qseq.txt; do
echo FILE = ${FILE}
ls -l ${FILE}
mkdir -p Users/mydir
awk '{ gsub(/\./,"N"); print }' ${FILE} > Users/mydir/${FILE}
echo before
cat ${FILE}
echo after
cat Users/mydir/${FILE}
done
$
$ ./script.sh
FILE = s_7_1_00_qseq.txt
-rw-r--r-- 1 tony tony 37 2009-05-25 09:31 s_7_1_00_qseq.txt
before
m.m.m.m.m.m.m.m.m
n.n.n.n.n.n.n.n.n.
after
mNmNmNmNmNmNmNmNm
nNnNnNnNnNnNnNnNnN
FILE = s_7_1_01_qseq.txt
-rw-r--r-- 1 tony tony 37 2009-05-25 09:31 s_7_1_01_qseq.txt
before
m.m.m.m.m.m.m.m.m
n.n.n.n.n.n.n.n.n.
after
mNmNmNmNmNmNmNmNm
nNnNnNnNnNnNnNnNnN
$
I have changed the target directory to be under my urrent directory for the purposes of testing.
Thanks to all of you. I got it to work.
Has anyone heard of SELCOPY? It is a general purpose programming tool commercially available. Things like file search and change is really easy for it and simpler than standard Unix tools.