NS-2相关工具大体介绍<1>

本文介绍gawk命令在文件处理中的应用实例,包括数据筛选、条件求和及字段打印等功能,展示了gawk的强大处理能力。

1. gawk对文件的处理能力很强,它主要用来进行数据分析和统计

命令格式为gawk 'program' input-file

第一个文件是BBS-LIST.TXT 下面是里面的内容:

=====================================

aardvark     555-5553     1200/300           B
alpo-net     555-3412     2400/1200/300      A
barfly       555-7685     1200/300           A
bites        555-1675     2400/1200/300      A
camelot      555-0542     300                C
core         555-2912     1200/300           C
fooey        555-1234     2400/1200/300      B
foot         555-6699     1200/300           B
macfoo       555-6480     1200/300           A
sdace        555-3430     2400/1200/300      A
sabafoo      555-2127     1200/300           C

======================================

第二个文件名叫SHIPPED.TXT,下面是文件内容:

=====================================

Jan  13  25  15 115
Feb  15  32  24 226
Mar  15  24  34 228
Apr  31  52  63 420
May  16  34  29 208
Jun  31  42  75 492
Jul  24  34  67 436
Aug  15  34  47 316
Sep  13  55  37 277
Oct  29  54  68 525
Nov  20  87  82 577
Dec  17  35  61 401


Jan  21  36  64 620
Feb  26  58  80 652
Mar  24  75  70 495
Apr  21  70  74 514

======================================

下面是我举得几个小例子,其实还有很多 ,大家有兴趣可以自己去查看来学习

(1) gawk '/foo/ {print $0}' BBS-LIST.TXT   //输出含有‘foo’的记录,运行截图如下:



(2)gawk '$1=="Feb" {sum=$2+$3} END {print sum}' SHIPPED.TXT  //找到第一列中与Feb相等的 然后将其第二项与第三项相加,直到每一行都处理过为止END{print sum}的意思为所有输入读完以后,执行一次print sum命令,运行截图如下:




(3)gawk '$1~/foo/ {print $0}' BBS-LIST.TXT  // BBS-LIST.TXT中第一栏的每个记录做检查,如果含有子串‘foo’ 编将这一记录打印出来,运行截图如下




(4) gawk 'BEGIN {OFS=";"; ORS="\n\n"} /foo/ {print $1,$2}' BBS-LIST.TXT  //打印每个记录的第一栏和第二栏,两栏之间用;隔开,每行输出后加一个空白行,运行截图如下


<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://java.sun.com/xml/ns/j2ee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"--> <!-- version="2.4">--> <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5.xsd" version="5.0"> <display-name>howie2</display-name> <filter> <filter-name>hmvc</filter-name> <filter-class>com.howie.hmvc.DispatcherFilter</filter-class> </filter> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.jhtml</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.aj</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.ar</url-pattern> </filter-mapping> <jsp-config> <taglib> <taglib-uri>asy</taglib-uri> <taglib-location>/WEB-INF/anshuyun.tld</taglib-location> </taglib> </jsp-config> <error-page> <error-code>404</error-code> <location>/error/404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error/500.jsp</location> </error-page> <session-config> <session-timeout>20</session-timeout> <!-- <cookie-config> <secure>true</secure> </cookie-config> --> </session-config> <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <http-method>HEAD</http-method> <http-method>OPTIONS</http-method> <http-method>TRACE</http-method> </web-resource-collection> <au
最新发布
03-20
### Jakarta EE 中 `web.xml` 的配置详解 #### 过滤器映射 (`<filter-mapping>`) 过滤器用于拦截特定请求并执行预处理或后处理逻辑。以下是 `<filter-mapping>` 的典型配置示例: ```xml <filter> <filter-name>SecurityFilter</filter-name> <filter-class>com.example.SecurityFilter</filter-class> </filter> <filter-mapping> <filter-name>SecurityFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> ``` 上述配置表示名为 `SecurityFilter` 的过滤器将应用于所有以 `.do` 结尾的 URL 请求[^1]。 --- #### 错误页面设置 (`<error-page>`) 错误页面用于捕获应用程序中的异常或 HTTP 响应状态码,并重定向到自定义页面。以下是一个常见的配置示例: ```xml <error-page> <error-code>404</error-code> <location>/errors/not-found.jsp</location> </error-page> <error-page> <exception-type>java.lang.Exception</exception-type> <location>/errors/generic-error.jsp</location> </error-page> ``` 此配置表明当发生 404 错误时,用户会被引导至 `/errors/not-found.jsp` 页面;而任何抛出 `java.lang.Exception` 类型的异常都会被导向 `/errors/generic-error.jsp` 页面[^3]。 --- #### 安全约束 (`<security-constraint>`) 安全约束用于保护 Web 应用程序中的资源,确保只有经过身份验证的用户才能访问某些路径。下面是一段典型的配置: ```xml <security-constraint> <display-name>Admin Pages</display-name> <web-resource-collection> <web-resource-name>Protected Area</web-resource-name> <url-pattern>/admin/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>Example Realm</realm-name> </login-config> <security-role> <role-name>admin</role-name> </security-role> ``` 在此配置中: - 所有匹配 `/admin/*` 路径的 GET 和 POST 请求都需要管理员角色权限。 - 使用 BASIC 认证方法进行登录认证。 - 定义了一个名为 `admin` 的安全角色。 --- #### 综合示例 以下是一个完整的 `web.xml` 文件片段,综合展示了过滤器映射、错误页面和安全约束的配置: ```xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" version="5.0"> <!-- Filter Mapping --> <filter> <filter-name>LoggingFilter</filter-name> <filter-class>com.example.LoggingFilter</filter-class> </filter> <filter-mapping> <filter-name>LoggingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Error Page Configuration --> <error-page> <error-code>404</error-code> <location>/errors/not-found.html</location> </error-page> <error-page> <exception-type>java.sql.SQLException</exception-type> <location>/errors/database-error.html</location> </error-page> <!-- Security Constraint --> <security-constraint> <web-resource-collection> <web-resource-name>Secure Resources</web-resource-name> <url-pattern>/secure/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>user</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <form-login-config> <form-login-page>/login.jsp</form-login-page> <form-error-page>/login-failed.jsp</form-error-page> </form-login-config> </login-config> <security-role> <role-name>user</role-name> </security-role> </web-app> ``` --- #### 注意事项 - **过滤器优先级**:多个过滤器可能会应用在同一组 URL 上,其执行顺序由它们在 `web.xml` 文件中的声明顺序决定。 - **安全性最佳实践**:建议使用 HTTPS 来加密敏感数据传输,并定期审查安全策略以防止潜在漏洞。 - **事务管理**:对于涉及数据库的操作,需注意事务隔离级别的设定,以免引发诸如第二类丢失更新等问题[^4]^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值