在程序当前目录下建一个txt文件bill.txt,文件内录入以下内容:
<pay_flowid>CTC4789</pay_flowid>
<>嗨,百度知道<dd>
<he和> hello linux
运行程序后在当前目录下生成str.txt文件,可以提取。
程序代码如下:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define LEN 100 /* 字符数,可以根据需要自己定义 */
int main(void)
{
int fd
long len,i,flag,j
char num[LEN],string[LEN]
fd = open("bill.txt",O_RDWR)
len = read(fd,num,LEN) /* read string for bill.txt */
num[len] = '\0'
close(fd)
for(i=0,j=0i<leni++)
{
switch(num[i])
{
case '<':
{
flag=1
break
}
case '>':
{
flag=2
break
}
default:
{
if(flag==2)
{
string[j]=num[i]
j++
}
}
}
}
string[j] = '\0'
fd = open("str.txt",O_RDWR|O_CREAT,S_IRUSR|S_IWUSR)
if(fd)
{
write(fd,string,j)
close(fd)
}
return 0
}
shell脚本的一个例子,大概的意思应该不差:#!/bin/sh
echo /dev/sdb >$$.tmp
echo /dev/sdc >>$$.tmp
aa=`cat $$.tmp`
rm -rf $$.tmp2
for a in $aa
do
b="$a"1
echo $b >>$$.tmp2
done
bb=`cat $$.tmp2`
echo $bb
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)