Как я могу сохранить конкретное регулярное выражение в нескольких строках с использованием команды SED?

src=/the/source/file
set -- `head -1 $src`;
col1=$1 ; col2=$2 ; col3=$3; i=0;
grep -v "`head -1 $src`" $src | while read c1 c2 c3
  do
    echo -e "$col1=$c1\n$col2=$c2\n$col3=$c3" > file-$((i=i+1)).out ; 
  done

test

$ cat $src
Column1     Column2      Column3  
Row1_Col1   Row1_Col2   Row1_Col3  
Row2_Col1   Row2_Col2   Row2_Col3  
Row3_Col1   Row3_Col2   Row3_Col3
$ set -- `head -1 $src`; i=0; col1=$1 ; col2=$2 ; col3=$3; i=0; grep -v "`head -1 $src`" $src | while read c1 c2 c3 ; do echo -e "$col1=$c1\n$col2=$c2\n$col3=$c3\n" > file-$((i=i+1)).out ; done
$ cat file-1.out 
Column1=Row1_Col1
Column2=Row1_Col2
Column3=Row1_Col3
$ cat file-2.out 
Column1=Row2_Col1
Column2=Row2_Col2
Column3=Row2_Col3
$ cat file-3.out 
Column1=Row3_Col1
Column2=Row3_Col2
Column3=Row3_Col3
$ 
0
22.06.2019, 01:14
1 ответ

Я пытался методом проб и ошибок, и следующая команда сработала для моей цели

sed 's/\(^>.*\|\)\(gi.*\)\(|ref.*\)/>\2/g' myfile

Однако, как вы упомянули, команды awk и cut намного проще и практичнее в данном контексте.

0
28.01.2020, 04:11

Теги

Похожие вопросы