Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何将制表符分隔的数据(始终以字母开头)合并为一个字符串?_String_Tabs_Letter - Fatal编程技术网

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