We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# Insert  6 digits into a chart

on
Medium Priority
362 Views
Nee help in :
1.  add my 6 figure into my chart
2.  delete  name in a chart
66666  Gustavson        Ian     25      M       250000
88888 Anderson  Jane    Jane    38      F
need to delete the 1st Jane and insert 450000 under 250000.  Please help me the chart should look like this
66666  Gustavson        Ian     25      M       250000
88888  Anderson        Jane    38      F        450000

Comment
Watch Question

## View Solutions Only

CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
perl -i -pe 's/Jane\s+(Jane.*)/\$1\t450000/' chart

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
when i put in the command it came out like this
66666  Gustavson        Ian     25      M       250000
88888 Anderson  Jane  38       F       450000
Is there any way I can add space to line the chart up.
Commented:
awk '{ if (\$3~/Jane/) {print \$1"\t"\$2"\t"\$4"\t"\$5"\t"\$6"\t450000" }else {print \$0}}' <file>

if input isn't tab-separated, try this one:
awk '{ if (\$3~/Jane/) {print \$1"\t"\$2"\t"\$4"\t"\$5"\t"\$6"\t450000" }else {print \$1"\t"\$2"\t"\$3"\t"\$4"\t"\$5"\t"\$6}}' <file>

bye,

-XoF-
Commented:
another variant:
awk '(\$4=="Jane"){\$4=\$5;\$5=\$6;\$6="450000";}{printf("%-6s%-16s%-8s%-8s%-8s%s\n",\$1,\$2,\$3,\$4,\$5,\$6);}' chart

Commented:
btw:
Perhaps one of you has an idea (according to the given awk-suggestions, I guess not...;) ):
I was just wondering, whether awk provides a kind of "shift-operator" for the postional params/matches....

Commented:
> .. awk .. "shift-operator"
unfortunately no, at least I don't know of any
sometimes your simply can set a positional parameter "empty, like \$3=""; but that is gawk/nawk only
otherwise you have to loop
for(i=start;i<=NF;i++){\$(i-1)=\$i;}
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile