How to remove ^M in a uploaded text file?

本文介绍了一种使用Unix/Linux下的tr命令来移除从DOS格式上传的纯文本文件中的^M字符的方法。这些^M字符通常会导致SQL*Loader加载数据时出现问题或者在shell脚本中并发执行时发生错误。

In apps, it's common that user changes setting of FTP client so that uploaded DOS plain text file contains a ^M at the end of each line. Such ^M usually cause wrong data in table after sqlldr loads it, sometimes shell script containing such ^M will also error out in concurrent program. After some googling, I hit a command named 'tr'.
#export file_name=test.txt
#tr -d "[/r]" < $file_name  >$file_name.1
This removes ^M.

In my previous post Carrying filename and request_id into table when doing sqlldr, ^M causes wrong awk output. Since I need to append file_name,request_id at then end of each line. So I need to remove empty lines, which can also achieved by tr command, see follwonig command
#export file_name=test.txt
#tr -d "[/r]" < $file_name  >$file_name.1
#tr -s "[/n]" < $file_name.1  >$file_name.2
#mv $file_name.2 $file_name
finally , append filename and request_id using follwong command.
#cat $file_name | awk -F,  '{printf("%s/n",$0",'$v_req_id','$file_name'")}' > $file_name.dat

我在参加ctf新生赛,这是一道web题目,叫做ez??upload 给了一个网站http://160.30.231.222:33360/ 源代码是<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Upload</title> <style> body { font-family: Arial, sans-serif; background-color: #f2f2f2; } .container { max-width: 400px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .form-group { margin-bottom: 20px; } .form-group label { display: block; font-weight: bold; margin-bottom: 5px; } .form-group input[type="file"] { padding: 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; } .form-group input[type="submit"] { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; } .form-group input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>文件上传</h2> <form action="index.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label for="file">选择文件</label> <input type="file" name="file" id="file" /> </div> <div class="form-group"> <input type="submit" value="上传" /> </div> </form> </div> </body> </html> <!-- class.php --> Hacker? 把网站后缀加上/class.php得到<?php error_reporting(0); highlight_file(__FILE__); class hacker{ public $cmd; public $a; public function __destruct(){ if('hahaha' === preg_replace('/;+/','hahaha',preg_replace('/[A-Za-z_\(\)]+/','',$this->cmd))){ eval($this->cmd.'hahaha!'); } else { echo 'nonono'; } } } if(isset($_POST['file'])) { if(preg_match('/^phar:\/\//i',$_POST['file'])) { die("nonono"); } file_get_contents($_POST['file']); } ?> 我该怎么做才能找到flag,一步一步详细来讲,我是纯新手注意我是纯新手!
10-05
我在做一个web题目,叫做ez??upload 给了一个网站http://160.30.231.222:33367/ 源代码是<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Upload</title> <style> body { font-family: Arial, sans-serif; background-color: #f2f2f2; } .container { max-width: 400px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .form-group { margin-bottom: 20px; } .form-group label { display: block; font-weight: bold; margin-bottom: 5px; } .form-group input[type="file"] { padding: 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; } .form-group input[type="submit"] { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; } .form-group input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>文件上传</h2> <form action="index.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label for="file">选择文件</label> <input type="file" name="file" id="file" /> </div> <div class="form-group"> <input type="submit" value="上传" /> </div> </form> </div> </body> </html> <!-- class.php --> Hacker? 其中这个网站后面加/class.php会得到<?php error_reporting(0); highlight_file(__FILE__); class hacker{ public $cmd; public $a; public function __destruct(){ if('hahaha' === preg_replace('/;+/','hahaha',preg_replace('/[A-Za-z_\(\)]+/','',$this->cmd))){ eval($this->cmd.'hahaha!'); } else { echo 'nonono'; } } } if(isset($_POST['file'])) { if(preg_match('/^phar:\/\//i',$_POST['file'])) { die("nonono"); } file_get_contents($_POST['file']); } ?> 我是edge浏览器,我是纯新手刚刚下载了xampp,请你告诉我怎么做11111,详细,每一个步骤都要详细 注意!preg_match("/__HALT_COMPILER/i",FILE_CONTENTS)
最新发布
10-05
我在做一个web题目,叫做ez??upload 给了一个网站http://160.30.231.222:33367/ 源代码是<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Upload</title> <style> body { font-family: Arial, sans-serif; background-color: #f2f2f2; } .container { max-width: 400px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .form-group { margin-bottom: 20px; } .form-group label { display: block; font-weight: bold; margin-bottom: 5px; } .form-group input[type="file"] { padding: 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; } .form-group input[type="submit"] { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; } .form-group input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>文件上传</h2> <form action="index.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label for="file">选择文件</label> <input type="file" name="file" id="file" /> </div> <div class="form-group"> <input type="submit" value="上传" /> </div> </form> </div> </body> </html> <!-- class.php --> Hacker? 其中这个网站后面加/class.php会得到<?php error_reporting(0); highlight_file(__FILE__); class hacker{ public $cmd; public $a; public function __destruct(){ if('hahaha' === preg_replace('/;+/','hahaha',preg_replace('/[A-Za-z_\(\)]+/','',$this->cmd))){ eval($this->cmd.'hahaha!'); } else { echo 'nonono'; } } } if(isset($_POST['file'])) { if(preg_match('/^phar:\/\//i',$_POST['file'])) { die("nonono"); } file_get_contents($_POST['file']); } ?> 我是edge浏览器,我上传了一个可以绕过__HALT_COMPILER检测的并且伪造成jpg的文件,网页中出现了Saved to: /tmp/d0096ec6c83575373e3a21d129ff8fef.jpg,请你告诉我怎么做才能拿到flag,详细,每一个步骤都要详细
10-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值