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

leftridge1
leftridge1 asked
on
Medium Priority
362 Views
Last Modified: 2010-04-21
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

Please help!!!!!!!!!!
Comment
Watch Question

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.

Ask the Experts

Author

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.  
XoF
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-
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
XoF

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....
> .. 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;}
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

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

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.