如果我的文件包含这样的行
/some/random/file.csv:some string
/some/random/file2.csv:some string2
是否有某种方法可以获得仅在冒号之前具有第一部分的文件,例如
/some/random/file.csv
/some/random/file2.csv
我更喜欢使用bash one liner,但perl或python也可以。
答案 0 :(得分:56)
cut -d: -f1
或
awk -F: '{print $1}'
或
sed 's/:.*//'
答案 1 :(得分:32)
另一种纯粹的BASH方式:
> s='/some/random/file.csv:some string'
> echo "${s%%:*}"
/some/random/file.csv
答案 2 :(得分:15)
答案 3 :(得分:1)
另一种纯粹的Bash解决方案:
while IFS=':' read a b ; do
echo "$a"
done < "$infile" > "$outfile"
答案 4 :(得分:0)
这已被问过很多次,所以超过1000分的用户要求这个是一些奇怪的事 但只是为了展示另一种方式:
echo "/some/random/file.csv:some string" | awk '{sub(/:.*/,x)}1'
/some/random/file.csv
答案 5 :(得分:0)
这对我有用,你们可以试试
const plusParent = useRef(null);
const plusChild = useRef(null);
const minusParent = useRef(null);
const minusChild = useRef(null);
const detectRef = (button, comp) => {
switch (button) {
case '+':
return comp === 'parent' ? plusParent : plusChild;
case '-':
return comp === 'parent' ? minusParent : minusChild;
}
};
{row.map((button) => {
return (
<View>
<TouchableOpacity
ref={() => detectRef(button, 'parent')}
>
<Text>{button}</Text>
</TouchableOpacity>
</View>
);
})}