Простая команда, rename
из util-linux
, сделает это за вас, она заменит все случаи "txt" на "text" во всех файлах, соответствующих "*.txt":
rename txt text *.txt
Попробуйте это:
awk -F '[, ]' '{print $1","$2","$3","$4}' file
aa.com,1.21.3.4,string1,string2
bb.com,5.6.7.8,string1,string2
попробуй:
awk '{print $1, $2}' OFS=, infile
aa.com,1.21.3.4,string1,string2
bb.com,5.6.7.8,string1,string2
Если бы в таком случае у вас были пробелы -в первом или втором полях, вы бы сделали:
awk -F, '{ match($3, /[^ ]* +[^ ]*/);
bkup=substr($3, RSTART, RLENGTH);
gsub(/ +/, ",", bkup); # replace spaces with comma
print $1, $2, bkup
}' OFS=, infile
Объяснение:читать в человекawk
:
match(s, r [, a])
Return the position in s where the regular expression r occurs,
or 0 if r is not present, and set the values of RSTART and RLENGTH. (...)
substr(s, i [, n])
Return the at most n-character substring of s starting at I.
If n is omitted, use the rest of s.
RSTART
The index of the first character matched by match(); 0 if no
match. (This implies that character indices start at one.)
RLENGTH
The length of the string matched by match(); -1 if no match.
Это можно сделать следующим образом:
sed -ne 's/[[:blank:]]\{1,\}/,/;s//\n/;P' input-file.txt
awk -F "[, ]" '{print $1,$2,$3,$4;OFS=","}' file
F "[, ]"
Принимает как пробел, так и запятую в качестве разделителя полей, а ;OFS=","
устанавливает разделитель полей вывода в виде запятой.