adb shell if判断文件第二行字符是否为空
时间: 2023-06-29 19:06:51 浏览: 63
可以使用以下命令来判断文件的第二行是否为空:
```
if [ -z "$(sed -n '2p' /path/to/file)" ]; then
echo "Second line is empty."
else
echo "Second line is not empty."
fi
```
其中,`-z` 选项用于检查字符串是否为空,`sed -n '2p' /path/to/file` 用于提取文件的第二行,如果第二行为空,则输出 "Second line is empty.",否则输出 "Second line is not empty."。
你可以将 `/path/to/file` 替换为你实际的文件路径。
相关问题
adb shell if判断文件第二行字符是否为非空
可以使用以下命令来判断文件的第二行字符是否为空:
```
if [ -n "$(adb shell sed -n '2p' file.txt)" ]; then
echo "第二行非空"
else
echo "第二行为空"
fi
```
其中,`sed -n '2p'` 表示输出文件 `file.txt` 的第二行,`-n` 表示不输出其他行,`2p` 表示输出第二行。
如果第二行非空,则条件判断为真,输出“第二行非空”,否则条件判断为假,输出“第二行为空”。
adb shell 判断文件第二行字符是否为空
可以使用以下命令来判断文件的第二行字符是否为空:
```
adb shell 'sed -n "2{p;q;}" file.txt | tr -d " \t\n\r" | wc -m'
```
其中,`file.txt`是要判断的文件名。这个命令的作用是:
1. `sed -n "2{p;q;}" file.txt` 取出文件的第二行。
2. `tr -d " \t\n\r"` 将第二行中的空格、制表符和换行符删除。
3. `wc -m` 统计删除后的字符串的长度。
如果第二行字符串长度为0,则表示第二行为空。如果长度大于0,则表示第二行不为空。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)