分页: 2 / 3
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 14:22
由 nishizawa23
for i in $(cat ufile); do find . $i; done
这样可以找到相对路径,可以,但是陷入死循环了
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 14:30
由 eexpress
locate 用 -r 限制下头文件的路径吧。
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 14:38
由 trigger
nishizawa23 写了:还是不行
应该是把cat ufile 认作字符串了
`cat ufile`反引号
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 15:27
由 nishizawa23
呵呵。没看清,不过不会用locate -r
locate -r /opt/u-boot-1.1.6 basename io.h
locate: non-option arguments are not allowed with --regexp
locate --regexp /opt/u-boot-1.1.6 basename io.h
locate: non-option arguments are not allowed with --regexp
不过用find倒是可以解决了
find . -name "*.c" | xargs grep ".*.h>$" | sed 's/\(.*\).<//g' | sed 's/>$//g' | sed 's/.*\///g' | sed '1 s/^/-name /' | sed '2,$ s/^/-o -name /' | sed '$ s/\\//' > tagstest
find . `cat tagstest`
结果还是不满意
例如某个c文件包含
#include <arm/io.h>
但是上面的程序是直接把io.h读出来,然后find的时候就把所有的io.h都读出来了
./include/ppc/io.h
./include/arm/io.h
./include/mips/io.h
有很多没用的头文件加进来
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 15:33
由 trigger
那就locate不加basename

Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 15:34
由 trigger
这么多sed,跑不动了

Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 15:44
由 nishizawa23
唉,折中方案,头文件应该都include的文件夹中
find . -name "*.c" | xargs grep ".*.h>$" | sed 's/\(.*\).</.\/include\//g' | sed 's/>$//g'
...
./include/command.h
./include/image.h
./include/zlib.h
./include/asm/byteorder.h
./include/asm/addrspace.h
./include/asm/io.h
./include/asm/setup.h
./include/asm/arch/platform.h
...
路径应该不会有错吧
没办法,不怎么会用bash
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 16:13
由 nishizawa23
问题出来了
lib_avr32/div64.c
中
#include <asm/div64.h>
find . -name div64.h
./include/asm-avr32/div64.h
这是为毛?
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 17:17
由 nishizawa23
再请教一下,一个字符串,最后一个字符只要匹配某个字符就为真,这个怎么写?
if [ ... ] ; then echo $i
括号里面怎么写?
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 17:34
由 trigger
好多种办法,正则可以,不正则也行
提示:echo "12345"|rev|cut -c 1
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-13 18:03
由 nishizawa23
ok!
for i in `cat mytags.files`; do if [ 'S' = `echo $i|rev|cut -c 1` ]; then echo $i; fi; done

Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-14 18:26
由 nishizawa23
那请问`echo $i|rev|cut -c 1`的正则表达式咋写的?

Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-15 15:31
由 trigger
str=asdfghj
$ echo $str | grep "j$"
asdfghj
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-15 15:34
由 gzbao9999
nishizawa23 写了:那请问`echo $i|rev|cut -c 1`的正则表达式咋写的?

echo $i|grep -Po ^.
Re: 如何利用shell从文件中读取文件路径
发表于 : 2010-08-15 15:42
由 trigger
gzbao9999 写了:nishizawa23 写了:那请问`echo $i|rev|cut -c 1`的正则表达式咋写的?

echo $i|grep -Po ^.
应该是
echo "$i"|grep -Po .$