String 如何将制表符分隔的数据(始终以字母开头)合并为一个字符串?
我的文件中包含以下数据:String 如何将制表符分隔的数据(始终以字母开头)合并为一个字符串?,string,tabs,letter,String,Tabs,Letter,我的文件中包含以下数据: col1 col2 col3 col4 col5 col6 ABC DEF GE-10 0 0 12 4 16 0 HIJ KLM 7 0 123 40 0 0 NOP QL 17 0 0 6 10 1 col1 col2 col3 col4 col5 col6 ABC DEF GE-10 0 0 12 4 16 0 HIJ KLM 7 0 123 40 0 0 NOP QL 17 0 0 6 10 1 我想将所有文本信息合并到一个字符串中(
col1 col2 col3 col4 col5 col6
ABC DEF GE-10 0 0 12 4 16 0
HIJ KLM 7 0 123 40 0 0
NOP QL 17 0 0 6 10 1
col1 col2 col3 col4 col5 col6
ABC DEF GE-10 0 0 12 4 16 0
HIJ KLM 7 0 123 40 0 0
NOP QL 17 0 0 6 10 1
我想将所有文本信息合并到一个字符串中(带uu-between),使其如下所示:
col1 col2 col3 col4 col5 col6
ABC_DEF_GE-10 0 0 12 4 16 0
HIJ_KLM 7 0 123 40 0 0
NOP_QL 17 0 0 6 10 1
问题是,某些行的第1-2列和某些行的第1-3列中存在要合并的文本信息
这是如何在Bash中实现的?test.js
#!/bin/bash.
file='read_file.txt'
#Reading each line
while read line; do
#Reading each word
wordString=""
count=1
for word in $line; do
if [[ $word =~ ^[0-9]+$ ]];then
#starts with a numberic value
wordString="${wordString} ${word}"
else
#doesn't starts with a numberic value
wordString="${wordString}_${word}"
fi
done
#remove first character and print the line
echo ${wordString#?}
done < $file
test.js
#!/bin/bash.
file='read_file.txt'
#Reading each line
while read line; do
#Reading each word
wordString=""
count=1
for word in $line; do
if [[ $word =~ ^[0-9]+$ ]];then
#starts with a numberic value
wordString="${wordString} ${word}"
else
#doesn't starts with a numberic value
wordString="${wordString}_${word}"
fi
done
#remove first character and print the line
echo ${wordString#?}
done < $file