I have a string that looks like this
username|field1|field2|field3
the data has a delimiter of "|"
how can i edit field1, keeping the rest of the data the same
also how can i edit field2 and 3.
I have a string that looks like this
username|field1|field2|field3
the data has a delimiter of "|"
how can i edit field1, keeping the rest of the data the same
also how can i edit field2 and 3.
edit in the sense you want to replace the first field with some other word keeping other intact??
if so use awk
echo "username|field1|field2|field3"|awk -F\| '{print "word|"$2"|"$3"|"$4}'
output will be
word|field1|field2|field3
same way you can do your second question also
> edit in the sense you want to replace the first field with some other word keeping other intact??
yup that was what i meant
that is very simple to understand.
thank you very much
No need for any external commands:
string="username|field1|field2|field3"
newfield1=something
newstring="$newfield1|${string#*|}"