#!/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
在程序当前目录下建一个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
}
FileOutputStreampublic FileOutputStream(String name,
boolean append)
throws FileNotFoundException创建向具指定 name 文件写入数据输文件流第二参数 true则字节写入文件末尾处写入文件始处创建新 FileDescriptor 象表示文件连接
首先安全管理器则用 name 作参数调用 checkWrite
该文件存目录规文件;或者该文件存创建;抑或其某些原打则抛 FileNotFoundException
参数:
name - 与系统关文件名
append - true则字节写入文件末尾处写入文件始处
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)