[英]How to get first string before blank string with shell script?
我有字符串列表
Facades core/app/Firstmedia/Facades/FmSettingFacades.php
core/app/Firstmedia/FmSettingFacades.php
core/app/Http/Controllers/Frontpage/ContentController.php
core/app/Http/Controllers/Frontpage/HomeController.php
core/app/Http/Controllers/Frontpage/OTPController.php
core/resources/views/admin/pages/solution/form.blade.php
core/resources/views/frontpage/pages/content.blade.php
core/routes/web.php
backend core/resources/views/backend/pages/content.blade.php
我只想在空白字符串之前獲取第一個字符串
預期 output:
Facades
backend
我試試這段代碼
#!/bin/bash
filename='copy.md'
n=1
tanggal=$(date +%d-%m-%Y)
tanggalWaktu=$(date +"%d-%m-%Y %H:%M:%S")
rm -rf ./update/$tanggal
mkdir -p ./update/$tanggal
mkdir -p ./logs
while read line; do
echo "$line" | awk '{sub(/:.*/,x)}1'
done < $filename
如果一行包含多於 1 列,則 output 第一列:
awk 'NF>1{print $1}'
awk
使用空格和制表符作為默認字段分隔符。
假設空白字符串表示一個或多個空格:
cut -f 1 -d ' ' "$filename"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.