Dedalus
1
Hi all,
I have a file like
one two three for
five six seven eight
.....
Actually i need to append a label to the words that belong to the 2 column and get:
one two_label three for
five six_label seven eight
....
I was trying with sed inside vim but I can't figure out a way.
Any help please?
Thx in advance
kurumi
2
$ ruby -ane '$F[1]=$F[1]+"_label";puts $F.join(" ")' file
$ awk '{$2=$2"_label"}1' file
1 Like
anbu23
3
sed "s/ *[^ ]*/&_label/" file
1 Like
cola
5
Why is the output not like that:
five six_label seven_label eight_label
Wh is _label appended only with the word "six" ?
If the output is like this:
five six_label seven_label eight_label
then where should the sed command be changed?
Aia
6
sed "s/ *[^ ]*/&_label/" file
doesn't have a global flag, therefore it matches only the first instance in each line.
sed "s/ *[^ ]*/&_label/g" file
Will just do what you originally thought
1 Like
awk '$2=$2 "_label" ' infile
sed 's|[^ ][^ ]*|&_label|2' infile
1 Like
ygemici
10
# cat file
onene two three for
five six seven eight
# sed 's/ *\(*.\)* */\1_label&/2' file
onene two_label three for
five six_label seven eight
Regards
ygemici